[R] How to plot error bars

ben@zoo.ufl.edu ben at zoo.ufl.edu
Thu Nov 9 14:22:38 CET 2000


  That's certainly a simpler solution.  It might be worth wrapping a few
arrows() calls up in some kind of simple errorbar function (just so it's
slightly more accessible to newcomers).  The only two things my function
did that these calls don't do is (1) to size the plot appropriately so the
upper and lower limits of the errors are within the plot, (2) to draw the
segments/arrows first so that one can add points with pch=19 and
bg=par("bg") to get open points without lines going through them.


On Thu, 9 Nov 2000, Emmanuel Paradis wrote:

> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> 
> 

-- 
318 Carr Hall                                bolker at zoo.ufl.edu
Zoology Department, University of Florida    http://www.zoo.ufl.edu/bolker
Box 118525                                   (ph)  352-392-5697
Gainesville, FL 32611-8525                   (fax) 352-392-3704

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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