0

I'd like to add the number count stat above each bar:

ggplot(data=diamonds, aes(x=color, fill=cut)) +
  geom_bar(position="dodge") +
  geom_text(aes(label=after_stat(count)), vjust=0)

It's giving me the error:

Error: Aesthetics must be valid computed stats. Problematic aesthetic(s): label = after_stat(count). Did you map your stat in the wrong layer?

pluke
  • 3,832
  • 5
  • 45
  • 68
  • Related, possible duplicate post? https://stackoverflow.com/q/6017460/680068 – zx8754 Jul 20 '21 at 10:56
  • 1
    Try with `geom_text(aes(label=after_stat(count)), vjust=0, stat = "count")`. Otherwise you have stat = "identity" and no "count" is computed. – stefan Jul 20 '21 at 11:36

0 Answers0