[R-sig-Geo] rasterVis: Region colours do not match the legend colours
Oscar Perpiñán Lamigueiro
oscar.perpinan at gmail.com
Thu Jul 4 19:56:45 CEST 2013
Hello,
Because the differences between layers are small, a suitable solution is to increase the
number of breaks:
library(raster)
library(rasterVis)
f <- system.file("external/test.grd", package="raster")
r <- raster(f)
r1 <- r + 100*runif(ncell(r))
r2 <- r - 100*runif(ncell(r))
s <- stack(r, r1, r2)
levelplot(s,
par.settings=rasterTheme(region=c('black', 'white', 'red')),
cuts=99)
Another approach is to display each layer with an independent legend:
http://rastervis.r-forge.r-project.org/FAQ.html#sec-7
Best,
Oscar.
jbaik writes:
> 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.
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
--
Oscar Perpiñán Lamigueiro
Grupo de Sistemas Fotovoltaicos (IES-UPM)
Dpto. Ingeniería Eléctrica (EUITI-UPM)
URL: http://procomun.wordpress.com
Twitter: @oscarperpinan
More information about the R-sig-Geo
mailing list