Reputation: 31
I have made a graph using ggplot from data I transformed into means with code:
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.
Upvotes: 1
Views: 5728
Reputation: 5114
You are almost there. This is based on se
as provided in Temperature
data:
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; there are also things like geom_crossbar
, geom_pointrange
and the like. See ?geom_errorbar
for help and some examples on all of them.
Upvotes: 3