[R] Constructing bar charts with standard error bars
Frank E Harrell Jr
f.harrell at vanderbilt.edu
Wed Jul 25 18:21:56 CEST 2007
John Zabroski wrote:
> I am new to R.
>
> I want to graph group data using a "Traditional Bar Chart with Standard
> Error Bar", like the kind shown here:
> http://samiam.colorado.edu/~mcclella/ftep/twoGroups/twoGroupGraphs.html
There are severe problems with dynamite plots such as these. See
http://biostat.mc.vanderbilt.edu/DynamitePlots for a list of problems
and solutions.
Frank
>
> Is there a simple way to do this?
>
> So far, I have only figured out how to plot the bars using barplot.
>
> testdata <- scan(, list(group=0,xbar=0,se=0))
> 400 0.36038 0.02154
> 200 0.35927 0.02167
> 100 0.35925 0.02341
> 50 0.35712 0.01968
> 25 0.35396 0.01931
>
> barplot(testdata$xbar, names.arg=as.character(testdata$group), main="a=4.0",
> xlab="Group", ylab="xbar")
> xvalues <- c(0.7, 1.9, 3.1, 4.3, 5.5)
> arrows(xvalues, testdata$xbar, xvalues, testdata$xbar+testdata$se, length=
> 0.4, angle=90, code=3)
>
>
> The best clue I have so far is Rtips #5.9:
> http://pj.freefaculty.org/R/Rtips.html#5.9 which is what I based my present
> solution off of.
>
> However, I do not understand how this works. It seems like there is no
> concrete way to determine the arrow drawing parameters x0 and x1 for a
> barplot. Moreover, the bars seem to be "cut off".
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
--
Frank E Harrell Jr Professor and Chair School of Medicine
Department of Biostatistics Vanderbilt University
More information about the R-help
mailing list