[R] Error Bars

Uwe Ligges ligges at statistik.uni-dortmund.de
Thu Nov 8 10:40:25 CET 2001

"Anon." wrote:
> I'm trying to draw some error bars on a bar chart.  I'm using code like
> this:
> thing <- c(3,3,3)
> se <- c(1,1,1)
> names(thing) <- c("A", "B", "C")
> barplot(thing, ylim=c(0,4))
> arrows(c(1:3), thing-se, c(1:3), thing+se, code=3, angle=90,length=0.1)
> Using c(1:3) has 2 problems:
> 1. Obviously it is untidy, but using names(thing) doesn't work, and I
> can't find out what will work.
> 2. It draws the lines in the wrong place (i.e. not in the middle of the
> bars)
> I'm sure this problem has a well know and obvious solution, but it's not
> so well known or obvious to me.

Barplot tells you where it has drawn the bars:

 temp <- barplot(thing, ylim=c(0,4)) 
 arrows(temp, thing-se, temp, thing+se, code=3, angle=90,length=0.1)

Uwe Ligges
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list