(v3.1.0.9020) Plot only the susceptible proportion in ggplot_sir() and geom_sir() if the interpretation is not shown, following the guideline

This commit is contained in:
dr. M.S. (Matthijs) Berends committed 2026-11-09 21:57:55 +01:00
1 parent 054066b855
commit 035c7e7871
6 files changed
+101 -43

No files matched your search

+16
View File
@@ -175,5 +175,21 @@ test_that("test-ggplot_sir.R", {
expect_equal(labels$y, (bars$ymin + bars$ymax) / 2)
}
}
# without the interpretation in the plot, only the susceptible proportion is shown, following the guideline
grouped <- example_isolates[, c("gender", "AMX")]
grouped <- structure(grouped, class = c("grouped_df", "tbl_df", "tbl", "data.frame"), groups = data.frame(gender = c("F", "M"), .rows = I(list(which(grouped$gender == "F"), which(grouped$gender == "M")))))
for (gl in list("EUCAST", "CLSI", NULL)) {
expected <- sir_df(grouped, guideline = gl)
expected <- expected[which(as.character(expected$interpretation) == levels(expected$interpretation)[1]), , drop = FALSE]
p <- ggplot_sir(grouped, x = "antibiotic", fill = "gender", position = "dodge", guideline = gl)
built <- ggplot_build(p)
expect_equal(sort(built$data[[1]]$y), sort(expected$value))
expect_equal(nrow(built$data[[2]]), nrow(expected))
expect_identical(p$labels$y, paste("Proportion", levels(expected$interpretation)[1]))
}
# all interpretations when they are shown in the facets
built <- ggplot_build(ggplot_sir(grouped, x = "antibiotic", fill = "gender", facet = "interpretation", position = "dodge", guideline = "EUCAST"))
expect_equal(nrow(built$data[[1]]), nrow(sir_df(grouped, guideline = "EUCAST")))
}
})