如何显示两组箱形图? [英] How to display two groups of boxplots?

查看:276
本文介绍了如何显示两组箱形图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两组数据(x1和x2与y1和y2),我想将其显示为两组箱线图。

I have two groups of data (x1 and x2 versus y1 and y2), which I would like to display as two groups of boxplots.

我尝试了以下操作,但是由于向量x1和x2(以及y1和y2)的长度不同,因此显示了错误的数据:

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")

这是显示的当然,根据x1的范围,我希望第一个箱形图的晶须从2变为4,等等。):

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.):

推荐答案

是的,或者您

lmts <- range(x1,x2,y1,y2)
par(mfrow = c(1, 2))
boxplot(x1, x2, ylim=lmts,names=c("x1","x2"),xlab="x")
boxplot(y1, y2, ylim=lmts,names=c("y1","y2"),xlab="y")

在完全基于评论...

On a complete side not based on the comments...

> quantile(c(2,3,4), type=1)
  0%  25%  50%  75% 100% 
   2    2    3    4    4 
> quantile(c(2,3,4), type=2)
  0%  25%  50%  75% 100% 
   2    2    3    4    4 
> quantile(c(2,3,4), type=3)
  0%  25%  50%  75% 100% 
   2    2    3    3    4 
> quantile(c(2,3,4), type=4)
  0%  25%  50%  75% 100% 
2.00 2.00 2.50 3.25 4.00 
> quantile(c(2,3,4), type=5)
  0%  25%  50%  75% 100% 
2.00 2.25 3.00 3.75 4.00 
> quantile(c(2,3,4), type=6)
  0%  25%  50%  75% 100% 
   2    2    3    4    4 
> quantile(c(2,3,4), type=7)
  0%  25%  50%  75% 100% 
 2.0  2.5  3.0  3.5  4.0 
> quantile(c(2,3,4), type=8)
      0%      25%      50%      75%     100% 
2.000000 2.166667 3.000000 3.833333 4.000000 
> quantile(c(2,3,4), type=9)
    0%    25%    50%    75%   100% 
2.0000 2.1875 3.0000 3.8125 4.0000 

这篇关于如何显示两组箱形图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆