[R] several boxplots or bwplots into one graphic

Christoph Lehmann christoph.lehmann at gmx.ch
Tue Jan 25 10:42:40 CET 2005


many thanks for your great tip. I didn't know reshape.

Unfortunately in my real data, the values of my variables are ont all 
within the same range. Therefore, what shall I change in the code to get 
for each plot a scale, which is adjusted to the range of my variable?

thanks a lot

christoph

Chuck Cleland wrote:
>   Your variables (var.*) seem to be on the same scale.  How about 
> reshaping the data into a univariate layout and then using bwplot as 
> follows:
> 
> mydata <- data.frame(ID = 1:20, A = runif(20), B = runif(20),
>                      C = runif(20), GROUP = rep(c(0,1), c(10,10)))
> 
> mydata.uni <- reshape(mydata, varying = list(c("A", "B", "C")),
>                       v.names = "Y", timevar = "VAR", times = c("A",
>                       "B", "C"), direction = "long")
> 
> library(lattice)
> 
> bwplot(Y ~ as.factor(GROUP) | VAR, data = mydata.uni, layout=c(3,1,1),
>        xlab="Group")
> 
> hope this helps,
> 
> Chuck Cleland
> 
> Christoph Lehmann wrote:
>> Hi
>> I have 10 variables and 2 groups. I know how to plot a bwplot for ONE 
>> var. e.g.
>>
>> var.a var.b var.c .. GROUP
>> 0.2   0.5   0.2   .. 0
>> 0.3   0.2   0.2   .. 0
>> ..
>> 0.1   0.8   0.7   .. 1
>> 0.5   0.5   0.1   .. 1
>> ..
>>
>>
>> bwplot(var.a ~ GROUP, data = my.data)
>>
>> How can I plot 10 bwplots (or boxplots) automatically into one 
>> graphic? is there any function from lattice which can do this?
>>
>> thanks for a short hint
>>
>> christoph
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide! 
>> http://www.R-project.org/posting-guide.html
>>
>




More information about the R-help mailing list