我有一个数据集,我想使用它创建两组箱线图ggplot2
封装如下图:
library(ggplot2)
df <- data.frame(f1=factor(rbinom(100, 1, 0.45), label=c("m","w")),
f2=factor(rbinom(100, 1, 0.45), label=c("young","old")),
boxthis=rnorm(100))
ggplot(aes(y = boxthis, x = f2, fill = f1), data = df) + geom_boxplot()
但是,我想使用不同的美学(未显示)为箱线图着色,或者根本不着色。我怎样才能将old
and young
在一起,但仍然有单独的箱线图f1
多变的。这是我想要做的事情的简化版本,所以我要求您的答案可以扩展到多个示例(例如,不仅仅是old
and young
,也许有 20 个不同的类别)。
Use the group
映射:
ggplot(aes(y = boxthis, x = f2, group = interaction(f1,f2)),
data = df) + geom_boxplot()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)