由两个条件分组的多个箱线图 [英] multiple boxplots grouped by two conditions

查看:59
本文介绍了由两个条件分组的多个箱线图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在单张绘图中制作多重箱形图时遇到了真正的麻烦...
我有五个变量,三个是数字变量,两个是因子。我想要所有三个数值变量的箱线图,但按两个因子变量分组...该图应具有两组,分别用于低和高,三个框分别用于MM,ND和BB。传说中应该包含MM,ND和BB的缩写。

I am having real trouble in making mutliple boxplots in single plot... I have five variables three are numeric and two are Factor. I want boxplot for all three numerical variables but grouped by the two Factor variable... The plot shoud have two groups each for Low and High with three boxes for MM, ND and BB. legends should contain the abbrevations for MM, ND and BB.

Group   Class   Sal Wal Daa
MM  Low 21  34  4
ND  Low 23  65  3
BB  High    21  34  2
MM  High    25  23  4
MM  High    23  23  5
MM  High    13  54  6
MM  High    56  32  4
MM  Low 34  13  3
ND  Low 12  35  7
ND  Low 34  34  2
ND  Low 54  54  1
ND  High    32  34  6
ND  High    43  32  7
BB  Low 54  13  3
BB  Low 12  56  2
BB  Low 45  34  6
BB  High    32  32  3
BB  High    13  12  2
BB  High    54  12  5


推荐答案

如果您希望每个数字变量都有单独的箱形图组,则可以使用 interaction()函数按组和类对变量分组:

If you want to have a separate group of boxplots for each numeric variable, you can use the interaction() function to group variables by Group and Class:

test.data <- data.frame(Sal=rnorm(100),
                        group=factor(sample(LETTERS[1:3], 100, replace=TRUE)),
                        class=factor(sample(c("low","high"), 100, replace=TRUE)))
boxplot(Sal ~ interaction(group,class), data=test.data)  

这篇关于由两个条件分组的多个箱线图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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