[R] errorbar il lattice plot
Federico Calboli
f.calboli at imperial.ac.uk
Fri Sep 28 13:27:18 CEST 2007
Hi Everyone,
I would like to add errorbars to a lattice plot. I already have a function that
adds error bars to a plot (originally written by George Gilchrist) which takes
as arguments the coordinates of the point and then the size of the error bar. I
would like to integrate it in my lattice code but I seem to be stumped.
I can put the error bar function inside my code as if it were a panel function,
but it then sits there quite unused. I am not even clear how what data object to
put the standard errors for the thing to work...
My code (the version that at least draws a plot):
xyplot(inbreeding~generations|breeds, data = trellisplot, type = 'l', layout =
c(2,5), col = 'black', lwd = 3,
errbar = function(x, y, err, down = T, width = 0.005, lwd = 1, plot = T,
colour="black")
{
up <- y + err
dn <- y - err
x.range <- max(x) - min(x)
wid.lf <- x - (x.range * width)
wid.rt <- x + (x.range * width)
if(plot == F) {
return(data.frame(x, up, dn))
}
else {
if(down == F) {
segments(x, up, x, y, lwd = lwd, lty = 1, col = colour)
segments(wid.lf, up, wid.rt, up, lwd = lwd, lty = 1, col = colour)
}
else {
segments(x, up, x, dn, lwd = lwd, lty = 1, col = colour)
segments(wid.lf, up, wid.rt, up, lwd = lwd, lty = 1, col = colour)
segments(wid.lf, dn, wid.rt, dn, lwd = lwd, lty = 1, col = colour)
}
invisible(data.frame(x, up, dn))
}
}
)
Regards,
Federico Calboli
--
Federico C. F. Calboli
Department of Epidemiology and Public Health
Imperial College, St Mary's Campus
Norfolk Place, London W2 1PG
Tel +44 (0)20 7594 1602 Fax (+44) 020 7594 3193
f.calboli [.a.t] imperial.ac.uk
f.calboli [.a.t] gmail.com
More information about the R-help
mailing list