Hi: Here's another approach using the reshape package:
library(reshape) # id defines the grouping variables; the others are stacked, creating # new variables 'variable' (containing the variable names as factor levels) and # 'value' (which holds the corresponding values) dfm <- melt(df, id = c('country', 'food')) # Strip off the leading 'X' and redefine as a factor with new levels dfm$year <- factor(gsub('X', '', dfm$variable), levels = 2000:2003) # Using foods as a groups = argument in xyplot(): xyplot(value ~ year | country, groups = food, data = dfm, type = c('p', 'l')) # Using country and food as conditioning variables xyplot(value ~ variable | country * food, data = dfm) HTH, Dennis On Thu, Feb 17, 2011 at 10:41 PM, Geoff Russell <geoffrey.russ...@gmail.com>wrote: > df=data.frame(country=c("A","A","A","B","B","B"), > food=rep(c("Apples","Pears","Bananas"),2), > X2000=c(4,5,6,7,6,8), > X2001=c(4,5,6,7,6,8), > X2002=c(4,5,6,7,6,8), > X2003=c(4,5,6,7,6,8)); > > I have data in the above form trying to get a plot of each fruit over time > year conditioned on country and food. > > I tried, > > xyplot(X2000+X2001+X2002+X2003~2000:2003|country*food,df) > > But think I need to transform the data, just not sure > how. Any help gratefully received. > > Cheers, > Geoff. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.