Java Mailing List Archive

http://www.r-help.com/

Home » R Help for Statistical Computing »

[R] simple plot in ggplot2, wrong error bars

Humberto Dutra

2010-03-11

Replies: Find Java Web Hosting

Author LoginPost Reply

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



--
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@(protected)
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
©2008 r-help.com - Jax Systems, LLC, U.S.A.