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

Chuck Cleland ccleland at optonline.net
Mon Nov 17 20:15:06 CET 2008


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

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



More information about the R-help mailing list