[R] Error bars.
Michael Camann
mac24 at humboldt.edu
Mon Jun 17 19:26:52 CEST 2002
Rolf et al.--
Here's a simple error bar function in R.
# produce vertical error bars on a plot-- aliased vbars in anticipation
# of the day when I need hbars to plot horizontal error bars....
#
# error bars originate at (x, y0) and radiate to y0 + y1 and y0 - y2
#
# example (adds +- 1.0 SE to a barplot of means for data vector x):
#
# y.mean <- mean(x) # mean
# y.se <- sqrt(var(x,na.rm=TRUE)/length(x)) # std err
# z <- barplot(y.mean,plot=FALSE) # location of bars
# barplot(y.mean,...) # the real plot
# ebars(z,y.mean,y.mean+y.se,y.mean-y.se) # add error bars
ebars <- vbars <- function (x, y0, y1, y2)
{
for(i in 1:length(x))
{
if(y0[i]!=0 & !is.na(y0[i]) & y1[i]!=0 & !is.na(y1[i]) &
(y0[i]!=y2[i]))
{
arrows (x[i], y0[i], x[i], y1[i], angle=90, length=0.05)
}
if(y0[i]!=0 & !is.na(y0[i]) & y2[i]!=0 & !is.na(y2[i]) &
(y0[i]!=y2[i]))
{
arrows (x[i], y0[i], x[i], y2[i], angle=90, length=0.05)
}
}
}
--Mike C.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Michael A. Camann Voice: 707-826-3676
Associate Professor of Zoology Fax: 707-826-3201
Institute for Forest Canopy Research Email: mac24 at axe.humboldt.edu
Department of Biology ifcr at axe.humboldt.edu
Humboldt State University
Arcata, CA 95521
URL:http://www.humboldt.edu/~mac24/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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