[R] An example of the boxplot thickness problem

Kenneth Roy Cabrera Torres krcabrer at une.net.co
Wed Nov 12 04:54:57 CET 2008


Hi R users:

I reproduce the problem that I have with the
boxplot thickness:
------------------------------------------------------------------
# A data frame:
set.seed(123)
cont1<-c(rnorm(10,1),rnorm(5,3),rnorm(12,5),rnorm(14,3),rnorm(4,5))
categ1<-factor(c(rep("A",10+5+12),rep("B",14+4)))
categ2<-c(rep("Z",10),rep("Y",5),rep("X",12),rep("Y",14),rep("X",4))

data1<-data.frame(cont1,categ1,categ2)

# This is the variable that I want that each boxplot
# be thickness proportional. (could be any other, the only
# condition is that I have a number (or NA) for each combination of the
# two categorical variables).
cont2<-tapply(cont1,list(categ1,categ2),length)/length(cont1)

require(lattice)
# This is the standard boxplot
bwplot(categ2~cont1|categ1,data=data1)
# I try:
bwplot(categ2~cont1|categ1,box.ratio=cont2,data=data1)
# This one also
bwplot(categ2~cont1|categ1,box.ratio=t(cont2),data=data1)
----------------------------------------------------------------

Problems: 
1. I expect that the boxplot for the B and Y combination
   would be the most thick, and in second place the A and X
   and the last the X and B combination.

2. Why the other lines in the box of the boxplot?

Thank you for your help.

Kenneth



More information about the R-help mailing list