[R] plot graph with error bars trouble

Ben Bolker bolker at ufl.edu
Sun Sep 30 20:20:53 CEST 2007


Marcelo Laia <marcelolaia <at> gmail.com> writes:

> 
> Hi,
> 
> I have a data set like this:
> 

 [snip]

> I need to plot a graph OD over the time for each one mutant with error bars.
> 
>


## I put your data in a temporary file, this reads it
x = read.table("tempdata.txt",header=TRUE)


## compute means and standard errors
##  (no built-in function for standard error, so create one)
## also see ?aggregate, ?by
means =  with(x,tapply(OD,list(Time,Mutant),mean))
se = function(x) sd(x)/sqrt(length(x))
ses = with(x,tapply(OD,list(Time,Mutant),se))

## time vector -- could also be unique(x$Time)
times = as.numeric(rownames(means))

## plot the means
matplot(times,means,type="b",lty=1,col=1:2,pch=1:2)
library(plotrix)
## have to create the x-vector and color-vector "by hand"
##  it would be nice if there were a matplotCI, but there
## isn't (yet) ...
plotCI(rep(times,2),means,ses,pch=NA,add=TRUE,
          col=rep(1:2,each=nrow(means)))

  good luck
   Ben Bolker



More information about the R-help mailing list