I need to have fixed number of decimals (two in this case) and I cannot make it work,
I am aware of using round
and accuracy
function but it does not seem to work for me
code:
library(ggplot2)
ggplot(mtcars, aes(factor(cyl))) +
geom_bar(color = "steelblue", fill = "#00AFBB", na.rm = T) +
scale_fill_discrete(drop=FALSE) +
scale_x_discrete(drop=FALSE) +
geom_text(aes(label=scales::percent(round(..count../sum(..count..),4))),
stat='count',vjust = -0.5, size = 4)