[R] lattice: problem with cex argument.
Deepayan Sarkar
deepayan.sarkar at gmail.com
Fri Mar 31 17:12:32 CEST 2006
On 3/31/06, ernesto <ernesto at ipimar.pt> wrote:
> Hi,
>
> I'm trying to plot a "bubbles" plot wich I do with the cex argument. The
> problem is that it looks like it fails the conditioning and reuses the
> first 100 elements of the cex vector. See the code
>
> x <- rep(rep(1:10,10),2)
> y <- rep(rep(c(1:10),rep(10,10)),2)
> z <- rep(1:2,c(100,100))
> w <- rpois(200,l=1)
> xyplot(y~x|z, cex=w)
>
> the plot has the same pattern in both sides but the data are different, see
>
> > tapply(w,z,summary)
> $"1"
> Min. 1st Qu. Median Mean 3rd Qu. Max.
> 0.00 0.00 1.00 0.99 1.00 4.00
>
> $"2"
> Min. 1st Qu. Median Mean 3rd Qu. Max.
> 0.00 0.00 1.00 0.95 2.00 4.00
>
> or the plots
>
> par(mfrow=c(1,2))
> tapply(w,z,hist)
>
> and
>
> xyplot(w~x|y*z)
>
> Is this a feature or a bug ?
Feature. The rule is simple: everything not relevant to the high level
function is sent to the panel function unchanged (this is normally
used to specify arguments of the panel function in the high level
call). Nothing outside the formula is `conditioned'. The panel
function will also be given, if requested, a 'subscripts' argument
that provides indices of the rows in the original data used in that
panel. Combining these you can condition anything you want inside the
panel function, e.g.
xyplot(y~x|z, cex = w,
panel = function(x, y, ..., cex, subscripts) {
panel.xyplot(x, y, ..., cex = cex[subscripts])
})
which is probably what you wanted. It took me a while to figure this
out, but I think this feature of the Trellis design solves very
elegantly a problem that would have been very hard to tackle directly.
Deepayan
More information about the R-help
mailing list