Show frequencies along with barplot in ggplot2

前端 未结 5 1006
既然无缘
既然无缘 2020-11-28 11:04

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 are

5条回答
  •  难免孤独
    2020-11-28 11:29

    geom_text is tha analog of text from base graphics:

    p + geom_bar() + stat_bin(aes(label=..count..), vjust=0, 
                              geom="text", position="identity")
    

    If you want to adjust the y-position of the labels, you can use the y= aesthetic within stat_bin: for example, y=..count..+1 will put the label one unit above the bar.

    The above also works if you use geom_text and stat="bin" inside.

提交回复
热议问题