From toby at abdn.ac.uk  Mon Mar 27 18:30:42 2006
From: toby at abdn.ac.uk (toby at abdn.ac.uk)
Date: Mon, 27 Mar 2006 18:30:42 +0200 (CEST)
Subject: [Rd] not a problem: a submission (PR#8714)
Message-ID: <20060327163042.A354B3EFF4@slim.kubism.ku.dk>

Full_Name: TOBY MARTHEWS
Version: 2.1.1
OS: Windows XP
Submission from: (NULL) (139.133.7.38)


I think you should have better examples on the ?plot man page, if you don't mind
me saying. Can I suggest something like this, which would probably stop so many
emails to the R help about how to put on error bars

Cheers,
Toby M
******************************

xvalsT1=1:3
yvalsT1=c(10,20,30)
errplusT1=c(2,3,4)
errminusT1=c(9,8,7)
xvalsT2=1:3
yvalsT2=c(30,35,40)
errplusT2=c(12,13,14)
errminusT2=c(1,2,3)
treatment=c(rep("T1",times=length(xvalsT1)),rep("T2",times=length(xvalsT2)))

xvals=c(xvalsT1,xvalsT2)
yvals=c(yvalsT1,yvalsT2)
errplus=c(errplusT1,errplusT2)
errminus=c(errminusT1,errminusT2)
RGR=data.frame(treatment,xvals,yvals,errplus,errminus)

minx=min(RGR$xvals);maxx=max(RGR$xvals)
miny=min(RGR$yvals-RGR$errminus);maxy=max(RGR$yvals+RGR$errplus)
plot(x=0,y=0,type="n",xlim=c(minx,maxx),ylim=c(miny,maxy),lab=c(2,4,0),xlab="month",ylab="Relative
Growth Rate",axes=FALSE)
axis(1,at=1:3,month.abb[1:3])        #axis(1,at=1:3,labels=c("Jan","Feb","Mar"))
has the
same effect
axis(2)

trts=c("T1","T2");syms=c(21,24)
for (i in 1:2) {
 A=subset(RGR,treatment==trts[i])
 points(x=A$xvals,y=A$yvals,pch=syms[i])
 segments(A$xvals,A$yvals-A$errminus,A$xvals,A$yvals+A$errplus)        #similar
to
symbols(x=A$xvals,y=A$yvals,boxplots=cbind(0,0,A$errminus,A$errplus,0.5),inches=FALSE,add=TRUE)
 errwidth=0.015
 segments(A$xvals-errwidth,A$yvals+A$errplus,A$xvals+errwidth,A$yvals+A$errplus)
 segments(A$xvals-errwidth,A$yvals-A$errminus,A$xvals+errwidth,A$yvals-A$errminus)
 lines(x=A$xvals,y=A$yvals,lty=syms[i])
}
#PS - this is a bit of an inelegant way to put on error bars, but to do better
you
#have to use commands like plotCI {gplots} or xYplot {Hmisc} - to learn more
look at
RSiteSearch("error bars")

legend(x=2.7,y=9,trts,pch=syms)        #in same units as the axes



[Rd] not a problem: a submission (PR#8714)
toby at abdn.ac.uk