[R-sig-Geo] rasterVis: Region colours do not match the legend colours

jbaik jon.baik at stat.ubc.ca
Thu Jul 4 19:28:12 CEST 2013


I want to compare several layer plots of a set of raster files that I have.
The problem is that the range of the data differs slightly for each file, so
the legends and colours are not directly comparable if I plot the rasters
side by side. For example, the range of data in raster A might be c(10, 90),
but raster B might have a range of c(0,100) - but then the regions in raster
A with values of 10 will be coloured the same as the regions in raster B
with values of 0!!

I tried modifying the plot using the "col.regions=", "at=" and "colorkey="
parameters in the "levelplot" command, but it does not seem to work.

Here is a reproducible example of my problem:


# Fix legend in raster plots
library(raster)
library(rasterVis)

f <- system.file("external/test.grd", package="raster")
r <- raster(f)

# The original levelplot
levelplot(r)

# Try to modify the legend and region colours
rgb.palette <- colorRampPalette(c("black", "white", "red"),
                                space = "rgb")

levelplot(r, col.regions=rgb.palette(16),
          at=seq(-30000, 30000, length=15) , contour=FALSE, 
          colorkey=list( at=seq(-30000, 30000, length=15), 
                         col=rgb.palette(16) ))



Notice that the original range of data is between approximately 0 and 2000.
In my second levelplot, I expand the range to -30000 and 30000. The legend
seems to reflect this, but the colours of the regions do not match the
legend!

How can I expand the range of the legend and force the regions to be
coloured properly?



--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/rasterVis-Region-colours-do-not-match-the-legend-colours-tp7584032.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list