My df looks like this:
Sede
<chr>
Mes
<S3: POSIXct>
n
<int>
Las Heras 2019-01-01 54
Las Heras 2019-02-01 53
Las Heras 2019-03-01 60
Las Heras 2019-04-01 56
Las Heras 2019-05-01 77
Las Heras 2019-06-01 98
Las Heras 2019-07-01 103
Las Heras 2019-08-01 88
Las Heras 2019-09-01 72
Las Heras 2019-10-01 75
Las Heras 2019-11-01 87
Las Heras 2019-12-01 52
Saavedra 2019-01-01 50
Saavedra 2019-02-01 50
Saavedra 2019-03-01 62
Saavedra 2019-04-01 89
And my code for the barplot:
ggplot(total_screening_mensual, aes(x = Mes, y = n, fill = Sede)) +
geom_col(position = "dodge") +
scale_fill_brewer(palette="Pastel1") +
geom_text(aes(group = Sede, label = n), position = position_dodge2(width = 1), hjust = 0, vjust = .5, size = 3) +
coord_flip() +
labs(title = "Estudios de screening por sede durante 2019",
x = "Mes",
y = "Cantidad de estudios")
My plot:
I want the text aligned with each column but cannot dodge the numbers. I have checked many similar questions but none of the answers seem to solve this problem and I don't understand where am I getting it wrong...
The problem is that you are attempting to dodge text on a continuous axis (your flipped x axis is a datetime axis), whereas you probably want this to be a discrete axis. So you can do something like this:
Data