[R] How to plot error bars

Emmanuel Paradis paradis at isem.univ-montp2.fr
Thu Nov 9 10:15:34 CET 2000

At 14:07 08/11/00 -0500, Ben Bolker wrote:
>  I'm going to take the liberty of reposting this function, which is based
>on one that Bill Venables posted a while back.  I've tweaked with it a bit
>to add functionality.  It will do horizontal bars or vertical bars, but
>not (yet) both simultaneously (the hardest thing about that is deciding on
>what format you want the data supplied in).
>  There's also a help file supplied below.
>  Should this (after appropriate tweaking/polishing/testing/revision) go
>into the main R code base?  It seems like a pretty basic function to me


>On Wed, 8 Nov 2000, Mike Beddo wrote:
>> I'm a newcomer to R. I can't seem to find any documentation how to add
>> error bars to points in scatter plots. I guess I could plot the points,
>> then compute and plot line segments in the X and/or Y directions to
>> represent the errors?
>> - Mike

I think using arrows(..., code=3, angle=90, ...) is quite simple, e.g.:

 	x <- rnorm(10)
 	y <- rnorm(10)
 	se.x <- runif(10)
 	se.y <- runif(10)
 	plot(x, y, pch=22)
 	arrows(x, y-se.y, x, y+se.y, code=3, angle=90, length=0.1)
 	arrows(x-se.x, y, x+se.x, y, code=3, angle=90, length=0.1)

The first arrows() draws the error bars for y, and the second one for x,
'code=3' draws a head at both ends of the arrow, 'angle=' is the angle of
the head with the main axis of the arrow, and 'length=' is the length of
the head. You can also add usual graphic parameters (col, lwd, ...).

Emmanuel Paradis
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