用点而不是条形图绘制直方图

发布于 2024-08-15 15:54:43 字数 128 浏览 2 评论 0原文

这是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

机场等船 2024-08-22 15:54:43

您可以自己快速完成此操作:

x <- c(1,1,2,1,2,3,3,3,4,4)
plot(sort(x), sequence(table(x)))

You can do this yourself pretty quickly:

x <- c(1,1,2,1,2,3,3,3,4,4)
plot(sort(x), sequence(table(x)))
暗恋未遂 2024-08-22 15:54:43

我知道的最简单的答案是:

x <- c(1,1,2,1,2,3,3,3,4,4)
stripchart(x,method="stack",at=0)

这比 Jonathan Chang 的建议更好,因为 stripchart 可以正确堆叠点。

The simplest answer I know is this:

x <- c(1,1,2,1,2,3,3,3,4,4)
stripchart(x,method="stack",at=0)

It's better than Jonathan Chang's suggestion because stripchart does proper stacking of points.

燕归巢 2024-08-22 15:54:43

Greg Snow 的教学演示包包含 dots(x, ...) 似乎适合您需要的功能:

dots( round( rnorm(50, 10,3) ) )

在此处输入图像描述

Greg Snow's TeachingDemos package contains a dots(x, ...) function which seems to fit your need:

dots( round( rnorm(50, 10,3) ) )

enter image description here

梨涡 2024-08-22 15:54:43

另一种简单的方法是:

x <- c(1,1,2,1,2,3,3,3,4,4)
myhist <- hist(x)
myhistX <- myhist$mids
myhistY <- myhist$density

现在您可以按照您喜欢的任何方式绘制它:

plot(myhistY~myhistX)

这样您可以在构建“直方图”对象时更改堆叠选项。

Another easy way would be:

x <- c(1,1,2,1,2,3,3,3,4,4)
myhist <- hist(x)
myhistX <- myhist$mids
myhistY <- myhist$density

And now you can plot it in any way you like:

plot(myhistY~myhistX)

This way you can change the stacking options when building a "histogram" object.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文