(v3.1.0.9019) Fix the data labels of labels_sir_count() being placed on the wrong bars with position = "dodge" or "stack"

This commit is contained in:
dr. M.S. (Matthijs) Berends committed 2026-11-09 21:52:40 +01:00
1 parent 77b6cb1713
commit 054066b855
6 files changed
+37 -5

No files matched your search

+15
View File
@@ -160,5 +160,20 @@ test_that("test-ggplot_sir.R", {
scale_sir_colours(aesthetics = "fill", Value4 = "S", Value5 = "I", Value6 = "R"))$data),
"data.frame"
)
# datalabels are placed on their own bar, also when dodged or stacked
for (pos in c("fill", "stack", "dodge")) {
built <- ggplot_build(ggplot_sir(example_isolates[, c("AMX", "CIP")], position = pos, guideline = NULL))
bars <- built$data[[1]]
labels <- built$data[[2]]
bars <- bars[order(bars$x, bars$group), , drop = FALSE]
labels <- labels[order(labels$x, labels$group), , drop = FALSE]
expect_equal(labels$x, bars$x)
if (pos == "dodge") {
expect_equal(labels$y, bars$ymax)
} else {
expect_equal(labels$y, (bars$ymin + bars$ymax) / 2)
}
}
}
})