On Fri, Feb 18, 2011 at 8:35 PM, Dennis Murphy <djmuser@gmail.com> wrote:

> 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)
>

Yes, this helps too. The reshape package seems a little clearer, to me at
least,
than the reshape function.

Many thanks,
Geoff.


>
> HTH,
> Dennis
>
> On Thu, Feb 17, 2011 at 10:41 PM, Geoff Russell <
> geoffrey.russell@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.
>>
>
>


-- 
6 Fifth Ave,
St Morris, S.A. 5068
Australia
Ph: 041 8805 184 / 08 8332 5069
http://perfidy.com.au

	[[alternative HTML version deleted]]

