Hello,
I created a random variable so anyone can see how the graph looks like.
So I get a space for the value "c" on my bar chart but I would like to add a 0%. Please note that this code will be included in a function to automatically generate graphs so I would like to avoid adding "0%" manually.
library(ggplot2)
vari <- factor(c("a", "a","b", "a", "a", "b"), levels=c("a","b","c"))
dfr <- as.data.frame(vari)
ggplot(dfr, aes(x=vari)) +
geom_bar() +
scale_x_discrete(drop=F)+
geom_text(aes(label = scales::percent(..prop.., accuracy=1), group = 1), stat= "count", vjust=-1, size=4)+
labs(y="Proportion of respondents")
Many thanks