[R] simple plot in ggplot2, wrong error bars
hpdutra
hpdutra at yahoo.com
Fri Mar 12 02:16:06 CET 2010
I was wondering if anyone could help me with this, simple problem.
I am essentially following the example on Hadley's webpage
(http://had.co.nz/ggplot2/geom_errorbar.html), but it still doesn't make any
sense to me.
df <- data.frame(trt = factor(c("intact", "intact", "removed", "removed")),
coon = c(0.093, 0.06, 0.057, 0.09), group = factor(c("veget", "fruit",
"veget", "fruit")), se = c(0.01, 0.01, 0.02, 0.026))
limits <- aes(ymax = coon + se, ymin=coon - se)
p<-ggplot(df, aes(fill=group, y=coon, x=trt))
p+geom_bar(position="dodge",stat="identity")
dodge <- position_dodge(width=0.9)
> p + geom_bar(position="dodge") + geom_errorbar(limits, position="dodge",
> width=0.5)
as you noticed the code above gets the error bars in the wrong columns.
So I used the code below (I replaced position_dodge w/ a negative value and
geom_errorbarr with dodge no quote marks)
df <- data.frame(trt = factor(c("intact", "intact", "removed", "removed")),
coon = c(0.093, 0.06, 0.057, 0.09), group = factor(c("veget", "fruit",
"veget", "fruit")), se = c(0.01, 0.01, 0.02, 0.026))
limits <- aes(ymax = coon + se, ymin=coon - se)
p<-ggplot(df, aes(fill=group, y=coon, x=trt))
p+geom_bar(position="dodge",stat="identity")
dodge <- position_dodge(width=-0.9)
> p + geom_bar(position="dodge") + geom_errorbar(limits, position=dodge,
> width=0.5)
Why do I need to use negative values to get the right errorbar structure,
why do I need use doge without quote marks?
Thanks
Beto
--
View this message in context: http://n4.nabble.com/simple-plot-in-ggplot2-wrong-error-bars-tp1589994p1589994.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list