0

我正在尝试绘制 ggplot 矩阵,箱线图版本工作得很好,但是当我尝试对 ggplot 做同样的事情时,我惨遭失败

箱线图版本:

par(mfrow=c(3, 3))
for (scale in c("POMS",
                "POMS_post",
                "DERS",
                "DERS_post",
                "REAPPRAISAL",
                "REAPPRAISAL_POST",
                "NEGATIV",
                "NEGATIVE_POST")) {
        boxplot(kata1[, scale] ~ Skupina, data=kata1, ylab=scale)
}

箱线图版本的结果: 在此处输入图像描述

ggplot 版本:

# Testing
for (scale in c("POMS",
                "POMS_post",
                "DERS",
                "DERS_post",
                "REAPPRAISAL",
                "REAPPRAISAL_POST",
                "NEGATIV",
                "NEGATIVE_POST")) {
        ggally_box(kata1, aes(Skupina, kata1[, scale])) # This does not work...
}

我认为这不应该那么困难,但我被卡住了。

谢谢你的帮助!

4

1 回答 1

0

在玩了一会儿之后,这解决了,尽管添加所有这些情节[[i]]是一种痛苦的方法。谢谢你的帮助。

plots = NULL
for (scale in c("POMS",
                "POMS_post",
                "DERS",
                "DERS_post",
                "REAPPRAISAL",
                "REAPPRAISAL_POST",
                "NEGATIV",
                "NEGATIVE_POST")) {
        plots[[scale]] = ggally_box(kata1, aes_string("Skupina", scale, color = "Skupina"), 
                                    outlier.colour = "red",
                                    outlier.shape = 13)
        }

grid.arrange(plots[[1]],plots[[2]],
             plots[[3]],plots[[4]],
             plots[[5]],plots[[6]],
             plots[[7]],plots[[8]], ncol = 2)
于 2015-11-10T16:11:42.133 回答