[R] An array of an array of boxplots in lattice

steve fisk at bowdoin.edu
Mon Nov 17 22:42:17 CET 2008


Thank you. Here's my version, using melt instead of do.call(make.groups...

library(reshape)
fgl2 = melt(fgl[,-10])
fgl2$type = fgl$type
bwplot(value ~ type | variable, data = fgl2)

Steve




Deepayan Sarkar wrote:
> On Mon, Nov 17, 2008 at 11:15 AM, Chuck Cleland <ccleland at optonline.net> wrote:
>> On 11/17/2008 1:50 PM, steve wrote:
>>> Using the data set fgl in MASS the following code
>>>
>>> layout(matrix(1:9,3,3))
>>> for(i in 1:9){
>>> boxplot(fgl[,i] ~ type, data = fgl,main=dimnames(fgl)[[2]][i])}
>>>
>>> produces a 3 by 3 array of plots, each one of which consists of six
>>> boxplots.
>>>
>>> Is it possible to do this in lattice?
>> library(MASS)
>> library(lattice)
>>
>> newdf <- reshape(fgl, varying =
>> list(c('RI','Na','Mg','Al','Si','K','Ca','Ba','Fe')),
>>                      v.names = 'Y',
>>                   times=c('RI','Na','Mg','Al','Si','K','Ca','Ba','Fe'),
>>                      direction='long')
> 
> And a slightly less verbose version of this step is:
> 
> newdf <- do.call(make.groups, fgl[-10])
> newdf$type <- fgl$type
> 
> followed by
> 
> bwplot(data ~ which | type, data = newdf, <etc.>)
> 
> -Deepayan
> 
>> bwplot(Y ~ type | time, data = newdf, ylab="",
>>           scales=list(y=list(relation='free')))
>>
>>> Steve
>>>
>>>  "R version 2.7.2 (2008-08-25)" on Ubuntu 6.06
>>>
>>> ______________________________________________
>>> R-help at 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.
>> --
>> Chuck Cleland, Ph.D.
>> NDRI, Inc. (www.ndri.org)
>> 71 West 23rd Street, 8th floor
>> New York, NY 10010
>> tel: (212) 845-4495 (Tu, Th)
>> tel: (732) 512-0171 (M, W, F)
>> fax: (917) 438-0894
>>
>> ______________________________________________
>> R-help at 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.
>>



More information about the R-help mailing list