[R] xyplot problem

Deepayan Sarkar deepayan.sarkar at gmail.com
Tue Sep 23 18:07:24 CEST 2008

On 9/23/08, Pascal A. Niklaus <pniklaus at ethz.ch> wrote:
> Hi all,
>  I am trying to produce some panels with dots in an X/Y plane where the
>  diameter of the dots indicates a Z value (like e.g. earthquake maps where dot
>  sizes indicate magnitudes and X/Y the location).
>  This works fine with xyplot, e.g.:
>  xyplot(1:3~1:3,cex=1:3,pch=16)
>  However, when I do this with a panel variable, e.g.:
>  x<-rep(1:3,5)
>  y <- rep(1:3,5)
>  sz <- rep(1:5,each=3)
>  grp <- factor(rep(1:5,each=3))
>  xyplot(y~x | grp , cex=sz)
>  then sz in the cex argument is not applied per group as I would expect. Same
>  for other arguments like col.
>  Is this really the intended behaviour?

Yes. Graphical arguments like 'cex' get passed to the panel function
directly, which needs to deal with it appropriately.

>  How can I achieve what I want, i.e., that the cex argument is different for
>  the different levels of grp?

Write your own panel function that extracts the appropriate subset of 'cex'.

xyplot(y~x | grp , cex=sz,
       panel = function(x, y, cex, subscripts, ...) {
           panel.xyplot(x, y, cex = cex[subscripts],
                        subscripts = subscripts, ...)


More information about the R-help mailing list