I’m trying to display frequencies within barplot … well, I want them somewhere in the graph: under the bars, within bars, above bars or in the legend area. And I recall (I may be wrong) that it can be done in ggplot2. This is probably an easy one… at least it seems easy. Here’s the code:
p <- ggplot(mtcars)
p + aes(factor(cyl)) + geom_bar()
Is there any chance that I can get frequencies embedded in the graph?
geom_textis tha analog oftextfrom base graphics:If you want to adjust the y-position of the labels, you can use the
y=aesthetic withinstat_bin: for example,y=..count..+1will put the label one unit above the bar.The above also works if you use
geom_textandstat="bin"inside.