如何显示两组箱线图?
我有两组数据(x1 和 x2 与 y1 和 y2),我想将其显示为两组箱线图。
我尝试了以下操作,但它显示了错误的数据,因为向量 x1 和 x2 (以及 y1 和 y2)的长度不同:
x1 <- c(2,3,4)
x2 <- c(0,1,2,3,4,5)
y1 <- c(3,4,5)
y2 <- c(1,2,3,4,5,6)
d0 <- matrix(c(x1, x2), ncol=2)
d1 <- matrix(c(y1, y2), ncol=2)
lmts <- range(d0,d1)
par(mfrow = c(1, 2))
boxplot(d0, ylim=lmts, xlab="x")
boxplot(d1, ylim=lmts, xlab="y")
这就是它显示的内容(当然,我希望第一个箱线图的须从2到4代替,根据x1的范围等):
I have two groups of data (x1 and x2 versus y1 and y2), which I would like to display as two groups of boxplots.
I tried the following, but it displays the wrong data because the vectors x1 and x2 (and y1 and y2) are not of the same lengths:
x1 <- c(2,3,4)
x2 <- c(0,1,2,3,4,5)
y1 <- c(3,4,5)
y2 <- c(1,2,3,4,5,6)
d0 <- matrix(c(x1, x2), ncol=2)
d1 <- matrix(c(y1, y2), ncol=2)
lmts <- range(d0,d1)
par(mfrow = c(1, 2))
boxplot(d0, ylim=lmts, xlab="x")
boxplot(d1, ylim=lmts, xlab="y")
This is what it shows (of course, I wanted the whiskers of the first boxplot to go from 2 to 4 instead, according to the range of x1, etc.):
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,或者你可以使用。
完整的一面不基于评论......
Yup, or you could have used.
On a complete side not based on the comments...
另一种选择是使用 ggplot2 包。您需要做更多的工作才能将数据放入一个 data.frame 中。但那就很容易了。
Another options is to use the ggplot2 package. You need a bit more work to put your data into one data.frame. But then it is very easy.