Kenneth Roy Cabrera Torres
2008-Nov-12 03:54 UTC
[R] An example of the boxplot thickness problem
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
On 11/11/08, Kenneth Roy Cabrera Torres <krcabrer at une.net.co> wrote:> 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.I think you want something like bwplot(categ2 ~ cont1 | categ1, data=data1, panel = function(..., box.width) { panel.bwplot(..., box.width = as.numeric(cont2[packet.number(), ])) })> 2. Why the other lines in the box of the boxplot?You are providing 6 width values for 3 boxes in each panel; the values are being recycled and each box is being drawn twice, with different widths. -Deepayan
Kenneth Roy Cabrera Torres
2008-Nov-12 09:56 UTC
[R] An example of the boxplot thickness problem
Dr. Sarkar:
Thank you very much for your help!
Is there any problem that it shows this warning message?
Warning messages:
1: In levels.fos - blist.height/2:
Length of object is greater or is not multiple
of the length of the shortest.
2: In levels.fos - blist.height/2:
Length of object is greater or is not multiple
of the length of the shortest.
El mar, 11-11-2008 a las 21:21 -0800, Deepayan Sarkar
escribi?:> On 11/11/08, Kenneth Roy Cabrera Torres <krcabrer at une.net.co>
wrote:
> > 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.
>
> I think you want something like
>
> bwplot(categ2 ~ cont1 | categ1, data=data1,
> panel = function(..., box.width) {
> panel.bwplot(...,
> box.width = as.numeric(cont2[packet.number(), ]))
> })
>
> > 2. Why the other lines in the box of the boxplot?
>
> You are providing 6 width values for 3 boxes in each panel; the values
> are being recycled and each box is being drawn twice, with different
> widths.
>
> -Deepayan