[R] How to import time-series data
Gabor Grothendieck
ggrothendieck at gmail.com
Sun Feb 12 19:49:46 CET 2012
On Sun, Feb 12, 2012 at 12:35 PM, RichardSmith
<richardsmith404 at gmail.com> wrote:
>
> Gabor Grothendieck wrote
>>
>> Something seems to have gone wrong in the posting since we can't see
>> the sample data that seems to be intended to be part of the post.
> Sorry, I posted via Nabble using the 'raw' command, which got stripped out
> it seems. Here's a small sample of the data...
> plant,aphid,1,2,3,4
> pumpkin,1-2,0.065566,0.057844,0.08,0.086879
> pumpkin,1-3,0.107612,0.097272,0.11663,0.160499
> squash,1-4,0.126939,0.115003,0.140275,0.188829
>
> columns named 1,2,3,4 etc. correspond to the weight of an aphid after that
> many days on that plant. I want to be able to plot the growth of all aphids
> on one plot, grouped by plant.
>
Try this xyplot.zoo lattice graph. Time series are represented in
columns so we transpose the data and convert it to zoo. The screen=
argument available in xyplot.zoo groups series into panels:
Lines <- "plant,aphid,1,2,3,4
pumpkin,1-2,0.065566,0.057844,0.08,0.086879
pumpkin,1-3,0.107612,0.097272,0.11663,0.160499
squash,1-4,0.126939,0.115003,0.140275,0.188829"
library(zoo)
library(lattice)
DF <- read.csv(text = Lines)
z <- zoo(t(DF[3:6]))
colnames(z) <- DF$aphid
xyplot(z, screen = DF$plant)
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
More information about the R-help
mailing list