一个简单的向量:
freq = c(1,2,2,3,3,3,4,4,4,4,5,5,5,5)
和一个简单的直方图:
ggplot(data=as.data.frame(freq), aes(x=freq)) + geom_histogram()
如何计算所有具有值的观测值,例如,>= 4并显示为一个条形图?谢谢。
发布于 2018-06-25 01:01:37
根据我的评论。只要检查一下,它就可以工作了,但是你必须在geom_histogram中指定'stat‘参数:
require(ggplot2)
freq = c(1,2,2,3,3,3,4,4,4,4,5,5,5,5)
ggplot(data=as.data.frame(freq), aes(x = freq >=4)) + geom_histogram(stat = 'count')
如果你想按值分组,你可以创建'cuts‘,如here所示
您也可以直接在ggplot中创建剪切:
ggplot(data=as.data.frame(freq), aes(x = cut(freq, c(1,2,3), include.lowest = TRUE))) +
#you need to make sure that the cuts actually represent the intervals you want!!
geom_histogram(stat = 'count')
发布于 2018-06-24 08:59:13
一种可能的方法是将所有值>= 4替换为4,然后绘制
freq[freq >=4] = 4
https://stackoverflow.com/questions/51005870
复制相似问题