[R] ggplot2, 'se' variable in geom_errorbar's limits?

Eric Fail eric.fail at gmx.com
Thu Feb 17 16:19:46 CET 2011


Dear R-list

I'm working with with geom_errorbar; specifically I'm trying to
reproduce the example Hadley Wickham have on
http://had.co.nz/ggplot2/geom_errorbar.html (all in the button of the
page) where he makes an nice plot with errorbars and then draw lines
between the points.

What confuses me is the 'limits' he defines for the errorbars from the
se variable.

First he creates a dataset,

df <- data.frame(
  trt = factor(c(1, 1, 2, 2)),
  resp = c(1, 5, 3, 4),
  group = factor(c(1, 2, 1, 2)),
  se = c(0.1, 0.3, 0.3, 0.2)
)

# library(ggplot2)

and then he creates some limits from the se variables.

limits <- aes(ymax = resp + se, ymin=resp - se)

[elements omitted]

# and then he creates the plot (I'm interested in).

p <- ggplot(df, aes(colour=group, y=resp, x=trt))
p + geom_line(aes(group=group)) + geom_errorbar(limits, width=0.2)

I can (of course) get Hadley's example to run, but I can't do it on my
data as I don't have a 'se' variable/don't know how to create it. I
have a group variable, a treatment variable, and a response variable,
but no se variable.

Could anyone out there explain how I create a 'se' variable in my data?

I'm sure my reasoning is the one that is off, and not ggplot2 (I'm a big fan).

Your help is appreciated!

Thanks,
Eric



More information about the R-help mailing list