用点而不是条形图绘制直方图
这是 R 用户的问题。我感兴趣的是绘制一个点堆积的直方图,而不是条形图。例如,如果数据是 (1,1,2,1,2,3,3,3,4,4),那么我希望看到三个点堆叠在 1 处,2 个点堆叠在 2 处,依此类推。在 R 中执行此操作的最佳方法是什么?
Here is a question for R-users. I am interested in drawing a histogram with points stacked up, instead of a bar. For example if the data is (1,1,2,1,2,3,3,3,4,4), then I would like to see three points stacked up at 1, 2 points stacked up at 2 and so on. What is the best way to do this in R?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以自己快速完成此操作:
You can do this yourself pretty quickly:
我知道的最简单的答案是:
这比 Jonathan Chang 的建议更好,因为
stripchart
可以正确堆叠点。The simplest answer I know is this:
It's better than Jonathan Chang's suggestion because
stripchart
does proper stacking of points.Greg Snow 的教学演示包包含 dots(x, ...) 似乎适合您需要的功能:
Greg Snow's TeachingDemos package contains a dots(x, ...) function which seems to fit your need:
另一种简单的方法是:
现在您可以按照您喜欢的任何方式绘制它:
这样您可以在构建“直方图”对象时更改堆叠选项。
Another easy way would be:
And now you can plot it in any way you like:
This way you can change the stacking options when building a "histogram" object.