[R] bwplot panels like stripplot

Deepayan Sarkar deepayan at stat.wisc.edu
Fri Sep 24 22:19:30 CEST 2004


On Friday 24 September 2004 14:45, Waichler, Scott R wrote:
> >> I would like to plot horizontal box-and-whisker plots in lattice
>
> where
>
> >> each factor has its own panel and scales are "free."  Below is a
> >> stripplot version of what I have in mind.  Substituting "bwplot"
> >> doesn't work.
> >
> > This won't work (easily) with R <= 1.9.1. Try with 2.0.0 beta, and
> > let
>
> us know if you still have problems.
>
> > Deepayan
>
> It still doesn't work.  Once again,
>
> > R.version.string
>
> [1] "R version 2.0.0, 2004-09-24"
>
> x <- c(runif(100, 0, 1), runif(100, 1, 2), runif(100, 2, 3))
> y <- c(rep("First", 100), rep("Second", 100), rep("Third", 100))
>
> # this works fine
> stripplot(x | y,
>           layout=c(1,3),
>           scales=list(relation="free"),
>           as.table=T,
>           bg="white"
>          )
>
> # this doesn't
> bwplot(x ~ y,
>        layout=c(1,3),
>        scales=list(relation="free"),
>        as.table=T,
>        bg="white",
>        horizontal=T
>       )
>
> Error in Ops.unit(do.call("max", lab.unit), tick.unit) :
>         Both operands must be units
> In addition: Warning messages:
> 1: x should be numeric in: bwplot(x ~ y, layout = c(1, 3), scales =
> list(relation = "free"),
> 2: no finite arguments to max; returning -Inf

I'm completely confused.

First of all, your two calls are not comparable -- stripplot has the 
`formula' x|y (which incidentally is undocumented and completely 
unreliable), while bwplot has x ~ y. 

Secondly, y is a character vector, which is inappropriate (you probably 
want it to be a factor). You might still have expected it to work, but 
to make things more complicated, horizontal=T, which means your 'x' 
should be the factor, which makes your 'y' completely uninterpretable.

The bwplot equivalent of your stripplot call (with the formula changed 
to a valid equivalent), namely

bwplot(~x | y,
       layout=c(1,3),
       scales=list(relation="free"),
       as.table=T,
       bg="white"
       )

works as expected for me. I have no idea what you expect bg="white" to 
achieve, though.

Deepayan




More information about the R-help mailing list