r - Create data labels for frequency plot in ggplot2? -
in this question, frequency figure can created using ggplot. 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 obtain data labels each individual bar within figure?
thank you.
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))
Comments
Post a Comment