0

In this question, a frequency figure can be created using ggplot. For example:

f <- factor(sample(letters[1:5], 100, r=T))
h <- table(f) / length(f)
dat <- data.frame(f = f)
ggplot(dat, aes(x=f, y=..count.. / sum(..count..), fill=f)) + geom_bar()

How do I now obtain data labels for each individual bar within the figure?

Thank you.

Community
  • 1
  • 1
user2716568
  • 1,866
  • 3
  • 23
  • 38

1 Answers1

2

You can add geom_text():

library(ggplot2)
ggplot(dat, aes(x=f, y=..count.. / sum(..count..), fill=f)) + 
  geom_bar() +
  geom_text(stat = "count", aes(label=..count../100))

enter image description here

mtoto
  • 23,919
  • 4
  • 58
  • 71