[R-sig-Geo] zlim argument image() does not work

Carsten Neumann carstennh at aol.com
Fri Dec 9 16:02:21 CET 2011


On 12/08/2011 09:54 PM, Roger Bivand wrote:
> On Thu, 8 Dec 2011, Carsten Neumann wrote:
>
>> Dear developers,
>
> The image.plot() function is in the fields package. image() and 
> spplot() methods in the sp package or image() methods in raster are 
> not the same, that is, they are methods called depending on their 
> (first) argument(s). image.plot() does not pass through a zlim= 
> argument, as you can see from its help page. You should have provided 
> a reproducible example. d1 is probably a SpatialGridDataFrame, since 
> you read it with readGDAL(), but image.plot() does not take this kind 
> of object as an argument. It may be that the ... in image.plot() does 
> get passed through to the legend building code, but its help page 
> suggests rather using breaks= to control the legend. This gets you 
> some way there:
>
> library(fields)
> x<- 1:10; y<- 1:15; z<- outer( x,y,"+")
> image.plot(x,y,z)
> brk<- quantile( c(z))
> image.plot(x,y,z, breaks=brk, col=rainbow(4))
> brk[1] <- 8
> brk[5] <- 19
> image.plot(x,y,z, breaks=brk, col=rainbow(4))
>
> and with more reading of the help page, you may get there. Also see:
>
> SGDF <- image2Grid(obj)
> image(SGDF, "z", zlim=c(8, 19), useRasterImage = FALSE)
>
> Roger
>
>>
>> the zlim argument in image() or image.plot() can be used to change 
>> the scale of the colorlegend. But this has no influence on the image 
>> that is plotted. Typically z values (Pixels) allocated to image data 
>> should change colors regarding min and max placed on the legend. But 
>> the plotted colors remains the same independently from changing 
>> colorlegends. Is this a known bug or did I overlook a detail:
>> ############################################################################# 
>>
>> sessionInfo()
>> R version 2.14.0 (2011-10-31)
>> Platform: x86_64-unknown-linux-gnu (64-bit)
>>
>> attached base packages:
>> [1] stats     graphics  grDevices utils     datasets  methods   base
>>
>> other attached packages:
>> [1] plotrix_3.3-1 fields_6.6.2  spam_0.27-0   rgdal_0.7-5   sp_0.9-91
>>
>> loaded via a namespace (and not attached):
>> [1] grid_2.14.0    lattice_0.20-0
>> ################################################################################ 
>>
>> d1<-readGDAL('NMS1_blue_neu.img')
>>
>> image.plot(d1,"band100",col=rainbow(200),zlim=c(0,200))
>> image.plot(d1,"band100",col=rainbow(200),zlim=c(0,1))
>>
>> ###means the legend is changing but the visualization of the images 
>> keeps the same and that is not a correct behavior###
>>
>> The same behavior I could observe in Raster Objects!
>>
>> Best regards
>>
>> Carsten
>>
>>
>
Dear all,

d1 is indeed a SpatialGridDataFrame and thank you "useRasterImage = 
FALSE" works to scale legend and image together with the "zlim" argument 
in functions image() and image.plot(). Unfortunately I could not find 
this argument on the function's help pages. The help pages did not grasp 
this zlim issue quite clear, so when comparing multiple images for one 
scale defined by zlim you might not see what you think to see. Just a 
hint, because it happened to me.

Thank you to Boris for your hint on raster package.

All the Best and thank you again

Carsten

-- 

Carsten Neumann
Telegrafenberg, A 17 01.13
14473 Potsdam
-------------------------------------------------------
Helmholtz Centre Potsdam
GFZ German Research Centre for Geosciences
Department 1 - Section 1.4 - Remote Sensing
-------------------------------------------------------
Tel.: +49 (0) 331 288 1766
e-mail: carstenn at gfz-potsdam.de



More information about the R-sig-Geo mailing list