如何从使用 ggplot() 构建的箱形图图形中删除胡须

How to delete whiskers from a box plot graphic built with ggplot()

我想从使用 ggplot() 包创建的箱线图中删除胡须。箱线图是使用自定义函数 MinMeanSEMMax 绘制均值和标准误差的。非常感谢您的帮助!
这是我使用的脚本:

MinMeanSEMMax <- function(x) {
  v <- c(min(x), mean(x) - sd(x)/sqrt(length(x)), mean(x), mean(x) + sd(x)/sqrt(length(x)), max(x))
  names(v) <- c("ymin", "lower", "middle", "upper", "ymax")
  v
}

ggplot(mtcars, aes(factor(am), mpg, fill=factor(am))) +
  stat_summary(fun.data=MinMeanSEMMax, geom="boxplot", colour="black") + 
  ggtitle("mtcars boxplot") + scale_fill_brewer(palette="OrRd")

您可以重新定义您的函数,以便 ymin = lowerymax = upper:

MinMeanSEMMax <- function(x) {
  v <- c(mean(x) - sd(x)/sqrt(length(x)), mean(x) - sd(x)/sqrt(length(x)), mean(x),
         mean(x) + sd(x)/sqrt(length(x)), mean(x) + sd(x)/sqrt(length(x)))
  names(v) <- c("ymin", "lower", "middle", "upper", "ymax")
  v
}

ggplot(mtcars, aes(factor(am), mpg, fill=factor(am))) +
  stat_summary(fun.data=MinMeanSEMMax, geom="boxplot", colour="black") + 
  ggtitle("mtcars boxplot") + scale_fill_brewer(palette="OrRd")