[R] A plotting question - how to get error bars?
toby at abdn.ac.uk
toby at abdn.ac.uk
Mon Mar 27 13:55:42 CEST 2006
Dear R list,
Can anyone help with a plotting question? I'm trying to display some data
on a plot and I've almost got the format I need (see code below), but 2
things I can't get:
1. How to get "Jan","Feb","Mar" on the x=axis instead of 1:3?
2. How to get "T"s on the end of my error bars like you have in standard
scientific plots?
Any comments gratefully received!
Thanks,
Toby
xvals=1:3 #couldn't get it to be "Jan, Feb, Mar" on the x-axis
rgrT1=c(10,20,30)
errbarsT1lo=c(0.5830952,0.3741657,0.8944272)
errbarsT1up=errbarsT1lo
rgrT2=c(25,30,35)
errbarsT2lo=c(1.356466,3.535534,1.140175)
errbarsT2up=errbarsT2lo
minx=min(xvals);maxx=max(xvals)
miny=min(rgrT1-errbarsT1lo,rgrT2-errbarsT2lo);maxy=max(rgrT1+errbarsT1up,rgrT2+errbarsT2up)
plot(x=0,y=0,type="n",xlim=c(minx,maxx),ylim=c(miny,maxy),lab=c(2,20,0),bty="l",xlab="month",ylab="Relative
Growth Rate")
points(x=xvals,y=rgrT1,pch=21)
symbols(x=xvals,y=rgrT1,boxplots=cbind(0,0,errbarsT1lo,errbarsT1up,0.5),inches=FALSE,add=TRUE)
#symbols does the error bars, but without the "T"s at the end. The
boxplot command does the Ts, but you can't have them without the box in
the middle (and you can't have different symbols for points either)
lines(x=xvals,y=rgrT1,lty=21)
points(x=xvals,y=rgrT2,pch=24)
symbols(x=xvals,y=rgrT2,boxplots=cbind(0,0,errbarsT2lo,errbarsT2up,0.5),inches=FALSE,add=TRUE)
lines(x=xvals,y=rgrT2,lty=24)
legend(x="right",c("Treatment 1","Treatment 2"),pch=c(21,24))
More information about the R-help
mailing list