Reputation: 1887
How can I annotate the following plot? I want to include counts on top of each bar.
g <- ggplot(mpg, aes(class))
# Number of cars in each class:
g + geom_bar()
I only know how to do it if I do a group by and create a new column 'count' for example.
Upvotes: 1
Views: 788
Reputation: 173793
You can do:
ggplot(mpg, aes(class)) +
geom_bar() +
geom_text(stat = "count", aes(label = after_stat(count)), nudge_y = 1)
Upvotes: 1