[R-sig-Geo] Issue with argument zlim() when plotting rasters
Boris Leroy
leroy.boris at gmail.com
Tue Nov 22 15:11:37 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
>>
>>
>Hi Boris,
>
>During my musings I found this :
>http://stackoverflow.com/questions/4316692/how-can-i-create-raster-plots-with-the-same-colour-scale-in-r
>
>This looks strangely similar to your problem...
>
>I hope this helps.
>
>Best,
>Arthur
Hi Arthur,
thank you for your answer.
Unfortunately I had also found this thread, but the solution proposed
doesn't work either.
The solution proposed in stackoverflow was to define the scale through
the breaks argument, which was already defined in my previous example.
It is strange because breaks and zlim() seemed to work for a lot of
people as I could see in several threads, but not here, or not
anymore.
Even the example given in the help of ?raster::plot does not seem to work.
Maybe my sessionInfo() could help:
R version 2.14.0 (2011-10-31)
Platform: i386-pc-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252
LC_MONETARY=French_France.1252
[4] LC_NUMERIC=C LC_TIME=French_France.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] raster_1.9-44 sp_0.9-91
loaded via a namespace (and not attached):
[1] grid_2.14.0 lattice_0.20-0 tools_2.14.0
Thanks for your help,
Boris
More information about the R-sig-Geo
mailing list