我想从使用ggplot()包创建的boxplot图形中删除胡须。箱形图用于使用自定义函数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")
答案 0 :(得分:4)
您可以重新定义您的功能,以便ymin = lower
和ymax = 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")