[英]How to group Boxplots without use of color or fill in ggplot2
I have a dataset that I would like to create two groups of boxplots using the ggplot2
package as shown below: 我有一个数据集,我想使用ggplot2
包创建两组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()
BUT, I want to color the boxplots using a different aesthetic (not shown) or not color them at all. 但是,我想使用不同的美学效果(未显示)为箱形图着色或完全不对它们着色。 How can I group the old
and young
together, but still have separate boxplots for the f1
variable. 如何将old
和young
归为一组,但是对于f1
变量仍然有单独的箱形图。 This is a simplified version of what I want to do, so I ask that your answer be expandable to multiple samples (eg more than just old
and young
, maybe 20 different categories). 这是我想做的事情的简化版本,所以我要求您的答案可以扩展到多个样本(例如,不仅仅是old
young
,也许有20种不同的类别)。
Use the group
mapping: 使用group
映射:
ggplot(aes(y = boxthis, x = f2, group = interaction(f1,f2)),
data = df) + geom_boxplot()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.