首页 > 解决方案 > 在R中将多个箱线图分组在同一个图中

问题描述

我试图在与“expertA”相同的图表中获得“expertB”的箱线图,但 y 轴应该保持 1、2、3、4、5、6 而不是 1,直到 12。颜色似乎也出错了,他们需要分开:专家A的一种颜色和专家B的另一种颜色。感谢帮助!

这是我的代码:

a <- dataset2010$`#ExpertA` 
b <- dataset2010$`#ExpertB` 

expA <- list(a[1:3],a[4:6],a[7:9],a[10:12],a[13:15],a[16:18])
expB <- list(b[1:3],b[4:6],b[7:9],b[10:12],b[13:15],b[16:18])

expAll <- c(expA, expB)

#Boxplot results expert A:
boxplot(expA, col=(c("lightblue")), 
        main= "Expert A", xlab ="Estimated value", ylab = "Question",
        horizontal = TRUE)

#Boxplot results expert B:
boxplot(expB, col=(c("lightgrey")), 
        main= "Expert B", xlab ="Estimated value", ylab = "Question",
        horizontal = TRUE)

#Trying to combine the boxplots:
boxplot(expAll, col=(c("lightblue", "lightgrey")), #"lightgreen", "yellow"
        main= "Expert ", xlab ="Estimated value", ylab = "Question",
        horizontal = TRUE)

这就是我得到的专家 A 的第一个箱线图

专家B的这个

这就是“试图结合箱线图”

标签: rgroupingboxplot

解决方案


推荐阅读