[R-sig-Geo] zlim argument image() does not work
Roger Bivand
Roger.Bivand at nhh.no
Thu Dec 8 21:54:58 CET 2011
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
>
>
--
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list