如何在图表上的直方图上显示每个bin的计数 [英] How to show count of each bin on histogram on the plot
本文介绍了如何在图表上的直方图上显示每个bin的计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想出了如何从ggplot中获取每个垃圾箱的数量,有人知道如何在绘图上显示这些数字吗?
I figured out how to get the count of each bin from ggplot, does anyone know how to show these numbers on the plot?
g <- ggplot()+geom_histogram()
ggplot_build(g)$data[[1]]$count
推荐答案
您可以添加stat_bin
来为您计算计数,然后将这些值用于标签和高度.这是一个例子
You can add a stat_bin
to do the calculations of counts for you, and then use those values for the labels and heights. Here's an example
set.seed(15)
dd<-data.frame(x=rnorm(100,5,2))
ggplot(dd, aes(x=x))+ geom_histogram() +
stat_bin(aes(y=..count.., label=..count..), geom="text", vjust=-.5)
这篇关于如何在图表上的直方图上显示每个bin的计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文