0

I found a script to make grouped barplots with ggplot. But I want it to label each bar with the count instead of the percentage.

I am using this code right now:

ggplot(data = subset(data, geb_nat!="nat" & !is.na(geb_use)), 
       aes(x = geb_typ, group = geb_use)) + 
  geom_bar(aes(y = ..prop.., fill = factor(..x..)), stat = "count") +
  geom_text(aes(label = scales::percent(..prop..), y = ..prop.. ),             
            stat = "count", vjust = -.5) +
  labs(y = "Percent", fill="geb_typ") +
  facet_grid(~geb_use) +
  scale_y_continuous(labels = scales::percent)

and this is the result:

Barplot

I want to show the actual count on top of the bars not the percentage

Z.Lin
  • 28,055
  • 6
  • 54
  • 94
  • 2
    Remove `scales::percent` and replace `..prop..` by `..count..`. You could further remove `stat="count"` because this is the default. – markus Jan 08 '19 at 18:32
  • Thank you, works good for me ! – Axeleration Jan 08 '19 at 20:26
  • 2
    Possible duplicate of [Showing data values on stacked bar chart in ggplot2](https://stackoverflow.com/questions/6644997/showing-data-values-on-stacked-bar-chart-in-ggplot2) – divibisan Jan 09 '19 at 21:42

0 Answers0