[R-sig-Geo] Issue with argument zlim() when plotting rasters

Boris Leroy leroy.boris at gmail.com
Mon Nov 21 12:08:35 CET 2011


Hi all,

I am trying to plot different rasters (same extent, different
resolutions), with the same color scale.

I have read the different threads aiming at specifying a single color
scale for different rasters and the simplest one seem to specify
zlim() when plotting.
I tried with the example I found in the help page of plot {raster}.

r <- raster(nrows=10, ncols=10)
r <- setValues(r, 1:ncell(r))
r[] <- runif(ncell(r))
r2 <- r/2
brks <- seq(0, 1, by=0.1)
nb <- length(brks)-1
par(mfrow=c(1,2))
plot(r, breaks=brks, col=rev(terrain.colors(nb)), lab.breaks=brks, zlim=c(0,1))
plot(r2, breaks=brks, col=rev(terrain.colors(nb)), lab.breaks=brks,
zlim=c(0,1))

It does not work as I expected: the scales are different between graphs.
The first graph has a scale from 0 to 1, and the second one has a
scale from 0 to 0.5. I expected to get a scale from 0 to 1 on both
graphs.
Is this a bug?  Or am I missing something?

Many thanks,

Boris


--
Boris Leroy,
PhD Student,
Equipe Biodiversité et Gestion des Territoires,
Service du Patrimoine Naturel, MNHN
UMR 7204 CERSP, MNHN
Université de Rennes 1
Campus de Beaulieu, Bât. 25, 1er étage
35042 Rennes cedex

+33 (0) 2 23 23 58 99
+33 (0) 6 66 02 13 27



More information about the R-sig-Geo mailing list