I think I found a problem with position_dodge() when the x-axis is a date.
When creating a bar plot with dodged groups and a date on the x-axis, I am unable to place counts above the bars like the example provided in the geom_text() documentation.
Here is the code to reproduce the bug:
df <- data.frame(
date <- as.Date(c("2025-01-01", "2025-01-01",
"2025-02-01", "2025-02-01")),
y = c(1, 3, 2, 1),
grp = c("a", "b", "a", "b")
)
ggplot(data = df, aes(date, y, group = grp)) +
geom_col(aes(fill = grp), position = "dodge") +
geom_text(aes(label = y), position = position_dodge(0.9))
I am using ggplot2 version 4.0.2.