I try to make a geom_bar figure and now I want the percentages by the bars. They are there, but not on the good place... Does anybody know how to fix that?
filter(D=="D") %>%
group_by(Operatiejaar, Ligging_compleet) %>%
summarise(cnt = n()) %>%
mutate(Percentage = formattable::percent(cnt / sum(cnt)))
ggplot(data=Data) +
aes(x=Operatiejaar, y=cnt, fill=Ligging_compleet, group = Operatiejaar) +
geom_bar(stat = "identity", width = 0.9, position = "dodge2") +
ggtitle(
label = "Ligging",
subtitle = "Verhoudingen") +
theme(
plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5)) +
xlab("Jaar") +
ylab("Aantallen") +
labs(fill = "Ligging") +
geom_text(
aes(label = Percentage, group = Operatiejaar),
color = "dark grey",
position = position_dodge(width = 1),
vjust = -0.5,
hjust = 0,
size = 3,
angle = 90)
The two things I prefer:
- Percentages above every bar
- Percentages round on zero decimals instead of the 2 decimals now