[R] x and y Error Bars

Ben Bolker bolker at ufl.edu
Fri Jul 31 21:09:12 CEST 2009




Sarah B wrote:
> 
> Hi All,
> 
> I have a question about plotting a one-to-one line and x-and-y error bars
> on a scatterplot for my data. I just can't seem to work it out!
> 
> 
> I have data from an experiment with 7 different treatment levels with 3
> replicates, that is set-out as follows:
> 
> Treatment Level    Replicate    Reponse-weight    Covariate-weight
> 1                            1                0.945                   
> 0.232
> 1                            2                0.345                   
> 0.213
> 1                            3                0.945                   
> 0.341
> 
> 2                            1                0.925                   
> 0.122
> 2                            2                0.115                   
> 0.110
> 2                            3                1.20                     
> 0.27
> 
> ... and so on..... for the 7 different treatment levels (21 rows
> altogether)
> 
> 
> I need to plot the means of each different treatment level on a
> scatterplot (Response-weight on y-axis and Covariate-weight on x-axis). I
> then need a one-to-one line added to the plot and x and y error bars. I
> have read the code for x-and-y error bars in Crawley's R book where he
> creates a function to apply the error bars - unfortunately, I can not
> understand how to adapt it to my dataset so I'm hoping someone would
> advise me of the simplest way to do this.
> 
> So my questions are:
> 1) How do I plot x-and-y error bars to my scatterplot of the above data?
> 2) How do I add a one-to-one line?
> 
> 

You can use  something like 

attach(mydata)
y.means = tapply(response,list(treatment),mean)
y.sd  = tapply(response,list(treatment),sd)
y.se = y.sd/sqrt(3)  ## since you know the numbers per treatment

x.means = tapply(covariate,list(treatment),mean)
## etc.

library(plotrix)
plotCI(x.means,y.means,2*y.se)
plotCI(x.means,y.means,2*x.se,add=TRUE,err="x")
abline(a=0,b=1) ## 1 to 1 line


-- 
View this message in context: http://www.nabble.com/x-and-y-Error-Bars-tp24760985p24761648.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list