using R.zoo to plot multiple series with error bars

Posted by dnagirl on Stack Overflow See other posts from Stack Overflow or by dnagirl
Published on 2010-06-11T18:41:01Z Indexed on 2010/06/12 10:02 UTC
Read the original article Hit count: 370

Filed under:
|
|
|

I have data that looks like this:

   > head(data)
             groupname ob_time dist.mean  dist.sd dur.mean   dur.sd   ct.mean    ct.sd
      1      rowA     0.3  61.67500 39.76515 43.67500 26.35027  8.666667 11.29226
      2      rowA    60.0  45.49167 38.30301 37.58333 27.98207  8.750000 12.46176
      3      rowA   120.0  50.22500 35.89708 40.40000 24.93399  8.000000 10.23363
      4      rowA   180.0  54.05000 41.43919 37.98333 28.03562  8.750000 11.97061
      5      rowA   240.0  51.97500 41.75498 35.60000 25.68243 28.583333 46.14692
      6      rowA   300.0  45.50833 43.10160 32.20833 27.37990 12.833333 14.21800

Each groupname is a data series. Since I want to plot each series separately, I've separated them like this:

> A <- zoo(data[which(groupname=='rowA'),3:8],data[which(groupname=='rowA'),2])
> B <- zoo(data[which(groupname=='rowB'),3:8],data[which(groupname=='rowB'),2])
> C <- zoo(data[which(groupname=='rowC'),3:8],data[which(groupname=='rowC'),2])

ETA:

Thanks to gd047: Now I'm using this:

    z <- dlply(data,.(groupname),function(x) zoo(x[,3:8],x[,2]))

The resulting zoo objects look like this:

> head(z$rowA)
          dist.mean  dist.sd dur.mean   dur.sd   ct.mean    ct.sd
     0.3  61.67500 39.76515 43.67500 26.35027  8.666667 11.29226
     60   45.49167 38.30301 37.58333 27.98207  8.750000 12.46176
     120  50.22500 35.89708 40.40000 24.93399  8.000000 10.23363
     180  54.05000 41.43919 37.98333 28.03562  8.750000 11.97061
     240  51.97500 41.75498 35.60000 25.68243 28.583333 46.14692
     300  45.50833 43.10160 32.20833 27.37990 12.833333 14.21800

So if I want to plot dist.mean against time and include error bars equal to +/- dist.sd for each series:

  • how do I combine A,B,C dist.mean and dist.sd?
  • how do I make a bar plot, or perhaps better, a line graph of the resulting object?

© Stack Overflow or respective owner

Related posts about r

    Related posts about plot