[R] Updating a hexbinplot
Deepayan Sarkar
deepayan.sarkar at gmail.com
Fri Feb 26 06:54:39 CET 2010
On Thu, Feb 25, 2010 at 1:24 AM, Marcin Kozak <nyggus at gmail.com> wrote:
> Dear all,
>
> Considering this simple example of hexbinplot:
> mixdata <-
> data.frame(x = c(rnorm(5000), rnorm(5000,4,1.5)),
> y = c(rnorm(5000), rnorm(5000,2,3)),
> a = gl(2, 5000))
> fig <- hexbinplot(y ~ x | a, mixdata)
> print(fig)
> update(fig, colramp = BTC)
>
> produces a bad (non-updated) legend. Compare it with:
>
> hexbinplot(y ~ x | a, mixdata, colramp = BTC)
>
> What should I do to update the plot with the correct legend?
Why not just use
hexbinplot(y ~ x | a, mixdata, colramp = BTC)
? In this (relatively simple) case, you could do
fig2 <- update(fig, colramp = BTC)
fig2$legend$right$args$colramp <- BTC
fig2
It should be possible to write an update method for hexbinplots to do
that automatically, but that doesn't happen currently (and I'm not
sure if it's worth the effort).
In general, an implicit assumption of the Trellis design is that the
panel display is independent of the legend. A much simpler example:
p <- xyplot(1:10 ~ 1:10, groups = gl(2, 5), auto.key = TRUE)
p
update(p, col = c("red", "blue"))
The simplest working solution in this case would be
update(p, par.settings = simpleTheme(col = c("red", "blue")))
but that actually involves several layers of patches on the original
design in S-PLUS (in particular, it actually changes the default
colors used by both panel and legend).
-Deepayan
More information about the R-help
mailing list