Add percentage labels to a stacked barplot

This would give you the asnwer:

ggplot(example.melt, aes(x=example.Category, y=value, fill = variable)) +
  geom_bar(position = "fill", stat = "identity",color="black",width=0.9) +
  scale_y_continuous(labels = scales::percent) +
  geom_text(aes(label = paste0(value*100,"%")), 
            position = position_stack(vjust = 0.5), size = 2)

Plot would look like this:

enter image description here

Leave a Comment