I'm trying to add the % symbol next to each label of a bar-plot showing count on the y-axis and factor levels on the x-axis. I have already calculated percentages values (pct) outside ggplot2 to use as labels, example here
My data
dat <-structure(list(GRADE = structure(1:5, .Label = c("0", "1", "2", "3",
"4"), class = "factor"), Count = c(151L, 31L, 31L,
9L, 2L), pct = c(67, 14, 14, 4, 1)), row.names = c(NA, 5L), class =
"data.frame")
Plot code
p <- dat %>%
ggplot(aes(x=GRADE, y=Count, fill=GRADE)) + geom_bar(stat="identity") +
geom_text(aes(label= pct), vjust=1.6, color="black", size=3.5) +
ggtitle("GRADE stage") + theme(plot.title = element_text(hjust = 0.5, size=14, face="bold")) +
scale_fill_brewer(palette="Blues") +
theme(legend.position="bottom")
p
Which gives this, but I want to add % next to 67, 14, 14, 4, 1 to show that these are percentages and not counts
p <- dat %>%
ggplot(aes(x=GRADE, y=Count, fill=GRADE)) + geom_bar(stat="identity") +
geom_text(aes(label= pct, "%"), vjust=1.6, color="black", size=3.5) +
ggtitle("GRADE stage") + theme(plot.title = element_text(hjust = 0.5, size=14, face="bold")) +
scale_fill_brewer(palette="Blues") +
theme(legend.position="bottom")
p
Which gives the wrong result here below
Any help appreciated, thanks!