r - How to add frequency count labels to the bars in a bar graph using ggplot2? -


this question has answer here:

i want plot frequency distribution of [r] factor variable bargraph, bars represent frequency counts of factor levels. use ggplot2 , there's no problem that.

what can't figure out how add frequency count labels bars in bargraph. syntax i've tried follows:

ggplot(data, aes(x = factorvar)) + geom_bar(fill = "somecolor") + geom_text(aes(y = ???)) 

i think thoroughly searched in stackoverflow , "r graphics cookbook" w.chang couldn't find specific answer parameter should match "y" in aesthetics of geom_text() above. tried variants like: (y = ..count..) didn't work.

i appreciate help. thanks...

ggplot(data=diamonds,aes(x=clarity)) + geom_bar() + geom_text(stat='bin',aes(label=..count..),vjust=-1) 

enter image description here


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -