[R-sig-Geo] colortables in raster

Michael Sumner mdsumner at gmail.com
Tue May 7 07:52:37 CEST 2013


Hello, I would like to use the @legend feature of raster to somehow
provide an absolute pallete across different objects. I thought
originally that I could just set the @legend at values and
@legend at colortable:


r <- raster(volcano)
r at legend@values <- seq(min(volcano), max(volcano), length = 125)
r at legend@colortable <- heat.colors(124)

## but, this doesn't work right since the getValues(r) should be
indices into r at legend@colortable
plot(r)

## we can recompute the values as indices, so it works
vs <- getValues(r)

r <- setValues(r, 1 + (124 * (vs - min(vs))/diff(range(vs))))
plot(r)

But, I would like to use the embedded legend like this in order to
keep the original range of getValues(r), but have the plotting build
the appropriate (absolute) colour map
from the @legend object. I'd also like it show the drawn legend when
the plot is done (like in .plotraster), rather than it being dropped
(as in .plotCT).

Is there any way to do this currently, other than to explicitly
provide the "col" and "breaks" arguments for plotting?  I appreciate
that I'm probably missing something obvious hacking around here.

Cheers, Mike.




--
Michael Sumner
Hobart, Australia
e-mail: mdsumner at gmail.com



More information about the R-sig-Geo mailing list