【发布时间】:2021-07-13 20:19:56
【问题描述】:
我想在 ggplot 中绘制一个具有不同 bin 宽度并且在 bin 之间没有间隙的直方图。就像在这个question 中一样,但在 GGPLOT 中。
Class Width Freq. Dist
0 <= x < 5 0.2
5 <= x < 15 0.1
15 <= x < 20 1.2
20 <= x < 30 0.4
30 <= x < 40 0.4
所以我希望 X 轴从 0-5,5-15,15-20,20-30 和 30-40 开始,并适当地绘制条形。
谢谢。
【问题讨论】:
-
可能有帮助:*.com/questions/20688376/…。你的数据已经这样总结了吗?您的原始输入数据到底是什么样的。你有休息的向量吗?
-
似乎与
geom_rect:data.frame(left = c(0,5,15,20,30),right=c(5,15,20,30,40),freq=c(.2, .1, 1.2, .4, .4)) %>% ggplot() + geom_rect(aes(xmin=left, xmax=right, ymin=0, ymax=freq), color="black", fill=NA)一起非常严格