[R] densityplot and panel.groups

Deepayan Sarkar deepayan.sarkar at gmail.com
Fri Jul 7 04:20:24 CEST 2006


On 7/6/06, Ken Beath <kbeath at efs.mq.edu.au> wrote:
> I am trying to plot multiple densityplots on each panel, and using
> panel.groups to do some additional plotting (not included in the
> example) as in this example.
>
> library(lattice)
>
> thedata <- data.frame(x=rnorm(1200),class=rep(1:3,each=200,times=2),
>         group=rep(1:2,each=100,times=6))
>
> densityplot(~x | class,groups=group,
>         xlab='x',
>         panel.groups = function(x,subscripts,groups,panel.number,...) {
>                 panel.densityplot(x=x,subscripts=subscripts,groups=groups,...)
> # other stuff here
>         },
>         plot.points=FALSE,
>         layout=c(3,1),
>         data=thedata)
>
> But get an "Error in panel.superpose(x, darg = darg, plot.points =
> plot.points, ref = FALSE,  : formal argument "panel.groups" matched
> by multiple actual arguments" using R 2.3.1 (MacOS X 10.4.7), I think
> this worked with a previous version of R.

Among the changes in lattice from a previous version is the following:

 o instead of ignoring it as before, 'panel.xyplot' and
   'panel.densityplot' now deal with a 'groups' argument appropriately
   by calling 'panel.superpose'.  Consequently, the default of 'panel'
   in 'xyplot' etc does not need to be conditional on 'groups'.

What you are seeing is a subtle side effect: panel.densityplot, which
is the default panel function in your call, does not allow a
'panel.groups' argument. You should additionally specify 'panel =
panel.superpose'.

Deepayan



More information about the R-help mailing list