ggplot/ally 使用 for 循环的箱线图
ggplot/ally boxplots using for loop
我正在尝试绘制 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...
}
我觉得应该不难,但我卡住了。
感谢您的帮助!
玩了一会儿之后就解决了,尽管添加所有这些情节是一种痛苦的方法[[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)
我正在尝试绘制 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...
}
我觉得应该不难,但我卡住了。
感谢您的帮助!
玩了一会儿之后就解决了,尽管添加所有这些情节是一种痛苦的方法[[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)