gpt4 book ai didi

r - 箱线图 schmoxplot : How to plot means and standard errors conditioned by a factor in R?

转载 作者:行者123 更新时间:2023-12-03 21:14:21 25 4
gpt4 key购买 nike

我们都喜欢中位数和四分位距等稳健的度量,但让我们面对现实,在许多领域,箱线图几乎从未出现在已发表的文章中,而均值和标准误差一直存在。

在lattice、ggplot2等中绘制箱线图很简单,而且画廊里到处都是。是否有一种同样直接的方法来绘制由分类变量决定的均值和标准误差?

我正在考虑这样的情节:

http://freakonomics.blogs.nytimes.com/2008/07/30/how-big-is-your-halo-a-guest-post/

或者在 JMP 中所谓的“平均钻石”(见图 3):

http://blogs.sas.com/jmp/index.php?/archives/127-What-Good-Are-Error-Bars.html

最佳答案

第一个情节刚刚覆盖在 blog post on imachordata.com 中. (帽子提示到 David Smith on blog.revolution-computing.com)您也可以 read the related documentation from Hadley on ggplot2 .

这是示例代码:

library(ggplot2)
data(mpg)

#create a data frame with averages and standard deviations
hwy.avg<-ddply(mpg, c("class", "year"), function(df)
return(c(hwy.avg=mean(df$hwy), hwy.sd=sd(df$hwy))))

#create the barplot component
avg.plot<-qplot(class, hwy.avg, fill=factor(year), data=hwy.avg, geom="bar", position="dodge")

#first, define the width of the dodge
dodge <- position_dodge(width=0.9)

#now add the error bars to the plot
avg.plot+geom_linerange(aes(ymax=hwy.avg+hwy.sd, ymin=hwy.avg-hwy.sd), position=dodge)+theme_bw()

它最终看起来像这样:
alt text

关于r - 箱线图 schmoxplot : How to plot means and standard errors conditioned by a factor in R?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1432867/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com