Dear Beto,
The code below gives a correct result.
library(ggplot2)
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))
ggplot(df, aes(x=trt, y=coon, fill = group, ymax = coon + se, ymin coon - se)) +
geom_bar(position = "dodge", stat="identity") +
geom_errorbar(position = "dodge")
------------------------------------------------------------------------
----
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek
team Biometrie & Kwaliteitszorg
Gaverstraat 4
9500 Geraardsbergen
Belgium
Research Institute for Nature and Forest
team Biometrics & Quality Assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
Thierry.Onkelinx at inbo.be
www.inbo.be
To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to
say what the experiment died of.
~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data.
~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of
data.
~ John Tukey
> -----Oorspronkelijk bericht-----
> Van: r-help-bounces at r-project.org
> [mailto:r-help-bounces at r-project.org] Namens hpdutra
> Verzonden: vrijdag 12 maart 2010 2:16
> Aan: r-help at r-project.org
> Onderwerp: [R] simple plot in ggplot2, wrong error bars
>
>
> 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-t
> p1589994p1589994.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
>
Druk dit bericht a.u.b. niet onnodig af.
Please do not print this message unnecessarily.
Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer
en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is
door een geldig ondertekend document. The views expressed in this message
and any annex are purely those of the writer and may not be regarded as stating
an official position of INBO, as long as the message is not confirmed by a duly
signed document.