[R] how to add error bar to the data in R?

Deepayan Sarkar deepayan at stat.wisc.edu
Tue Sep 7 01:02:04 CEST 2004


On Monday 06 September 2004 16:54, jz7 at duke.edu wrote:
> Dear all,
>
> Does anyone knwo how to add error bar to the data point in a simple
> xyplot? Right now, I have a .dat file including both the data points
> and their standard deviation and read it in R. I tried function
> arrows(). But it didn't gave me any arrows.

If you are talking about xyplot in the lattice package, you need to use 
larrows instead of arrows. e.g. your call might look like

xyplot(y ~ x, data, sd = data$sd,
       panel = function(x, y, subscripts, sd, ...) {
           larrows(x, y - 2 * sd[subscripts],
                   x, y + 2 * sd[subscripts],
                   angle = 90, code = 3, ...)
           panel.xyplot(x, y, ...)
       })

Alternatively, you could use xYplot in the Hmisc package.

Deepayan




More information about the R-help mailing list