ggplot,箱线图间距和stat_summary位置

时间:2020-04-30 14:43:55

标签: r ggplot2 boxplot

我尝试了多种选项组合,但均未成功。 我想:

1)将均值矩形的填充颜色更改为白色

2)将每个均值(矩形)定位在其自己的箱线图的中心

3)增加4组箱形图之间(而不是单个箱之间)的水平间距

  boxp <- ggplot(df[df$QG=="INV",], aes(qID, Val, fill=Cond)) +
      geom_boxplot(outlier.color = NA) +
      stat_summary(fun.y=mean, geom="point", shape=23, size=2, colour = "black") +
      labs(x = "Questions", y="Values", title = "Question subgroup", colour = "Conditions")
  boxp

enter image description here

mtcars的可复制示例

boxp <- ggplot(mtcars, aes(gear, disp, fill=vs)) +
  geom_boxplot(outlier.color = NA) +
  stat_summary(fun.y=mean, geom="point", shape=23, size=2, colour = "black") +
  labs(x = "Questions", y="Values", title = "Question subgroup", colour = "Conditions")
boxp

mtcars <- mutate_at(mtcars, c("carb", "gear", "vs"), as.factor)

0 个答案:

没有答案