[英]ggplot: Boxplot with fill and standard errors
這是箱線圖
ggplot(mtcars, aes(factor(cyl), mpg, fill=factor(am))) + geom_boxplot()
我想重現相同的圖,顯示平均值,一個標准誤差和兩個標准誤差,而不是中位數和分位數。
我做了
boxes <- function(x) {
#r <- quantile(x, probs = c(0.05, 0.25, 0.5, 0.75, 0.95))
meanx = mean(x)
n = length(x)
se = sqrt(var(x)/n)
r <- c( meanx-1.96*se, meanx-se, meanx, meanx+se, meanx+1.96*se )
names(r) <- c("ymin", "lower", "middle", "upper", "ymax")
r
}
ggplot(mtcars, aes(factor(cyl), mpg, fill=factor(am))) + stat_summary(fun.data=boxes, geom="boxplot")
問題在於,不同顏色的框重疊而不是並排放置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.