简体   繁体   English

向ggplot2添加错误栏

[英]Adding error bars to ggplot2

I have made a graph using ggplot from data I transformed into means with code: 我已经使用ggplot从我转换为带有代码的均值的数据中制作了一个图表:

I would like to know if there is anyway I can add error bars to this graph. 我想知道是否仍然可以向该图添加误差线。 I know I have to transform the data to have more summaries but not sure how to proceed. 我知道我必须转换数据以具有更多摘要,但不确定如何进行。 Tried to do it seperately for each column but could'nt make a graph from it. 试图为每一列单独执行此操作,但是无法从中创建图形。 like this: 像这样:

Temperature <- ddply(shlf, c("Location"), summarise,
                       N = length(temp),
                       mean.temp = mean(temp),
                       sd = sd(temp),
                       se = sd / sqrt(N))

Any help is appreciated. 任何帮助表示赞赏。

You are almost there. 你快到了。 This is based on se as provided in Temperature data: 这基于Temperature数据中提供的se

means$upper = Temperature$mean.temp + Temperature$se
means$lower = Temperature$mean.temp - Temperature$se

ggplot(means, aes(x = temp,
                  y = Triconia,
                  color = Location)) +
   geom_point(size = 5.0) +
   geom_errorbarh(aes(xmin = upper, xmax = lower))

Errorbar as a separate geom comes in distinct flavors: geom_errorbar is vertical and geom_errorbarh is horizontal; 作为单独的geom的Errorbar具有不同的风格: geom_errorbar是垂直的, geom_errorbarh是水平的; there are also things like geom_crossbar , geom_pointrange and the like. 还有诸如geom_crossbargeom_pointrange之类的东西。 See ?geom_errorbar for help and some examples on all of them. 请参阅?geom_errorbar以获取帮助和所有示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM