[R-sig-Geo] Optimize image plot of a grid with legend - colors - and extras ?

Edzer J. Pebesma e.pebesma at geo.uu.nl
Mon Jun 4 09:56:14 CEST 2007


Jan, I have a clue why this happened. Indeed,

 > image(input, col=rev(bpy.colors(10)), axes=T)

reproduces the example, but

 > image(input, col=rev(bpy.colors(10)))
 > axis(1)
 > axis(2)
 > box()

doesn't. It seems like the col argument is passed to axis, try

 > axis(1, col = rev(bpy.colors(10))

so indeed a specific color argument for the axes (as you suggest: 
col.axes) is needed here to override the plotting colors. Will work on 
it. Hope the solution above works for the moment.
--
Edzer

Jan.Verbesselt at csiro.au wrote:
> Hi Roger,
>
> I made a reproducible example: When you change the colors of the spatial
> image the colors of the axes also change. How could this be solved?
>
> (How can a legend and scale be added to this plot?)
>
> All other tips and tricks are mostly welcome,
>
> Thanks a lot,
> Jan
>
> Ps. Great that this sp() package make spatial analysis and visualization
> possible in R! - Does maptools package offer better or alternative
> mapping functions? 
>
> /***script***
>
> library(fields)
> library(sp)
>
> data(meuse.grid)
> coordinates(meuse.grid) = ~x+y
> gridded(meuse.grid) = TRUE
> data(meuse)
> coordinates(meuse) = ~x+y
> data(meuse.riv)
> plot(meuse.riv)
> meuse.sl = SpatialLines(list(Lines(list(Line(meuse.riv)))))
>
> ## image plot with points and lines
> nr <- 200
> ramp <- colorRamp(c("blue", "green"))
> kleur <- rgb( ramp(seq(0, 1, length = nr)), max = 255)
> par( mar=c(5,5,5,8))
> input <- meuse.grid["dist"]
> image(input, col=kleur, axes=T,main = "meuse river data set; colour
> indicates distance to river", col.axis=1)
> points(meuse, pch = 3)
> plot(meuse.sl, add=T)
> image.plot( zlim=c(min(input$dist),max(input$dist)),
> nlevel=nr,legend.only=TRUE, horizontal=F, col=kleur)
>
>
>
>
> -----Original Message-----
> From: Roger Bivand [mailto:Roger.Bivand at nhh.no] 
> Sent: Friday, 1 June 2007 7:01 PM
> To: Verbesselt, Jan (Ensis, Clayton)
> Cc: r-sig-geo at stat.math.ethz.ch
> Subject: Re: Optimize image plot of a grid with legend - colors - and
> extras ?
>
> On Fri, 1 Jun 2007 Jan.Verbesselt at csiro.au wrote:
>
>   
>> Thanks Roger,
>>
>> It's all working now ; I plotted a shape file on top of a spatial grid
>> image via the following script. Only, when you change the colors of
>>     
> the
>   
>> image() the axis colors also change. I couldn't solve this and tried
>> several options (par, axis(), etc), but nothing worked.
>>     
>
> In order to find this out, please provide an example with the meuse.grid
>
> dataset shipped with sp, and for the shape, the meuse.riv river contour.
>
> It may be that the col= argument is being passed through by accident to 
> plot.Spatial(), but without a reproducible example, it is difficult to 
> say.
>
> Roger
>
>   
>> I also used image.plot() of the fields library to add a legend to the
>> image.
>>
>> Does somebody has some advise how to optimize these type of spatial
>> image -grid plots with a legend, colors, and other extra's? 
>>
>> All examples are welcome,
>> Cheers and thanks,
>> Jan
>>
>>
>> # combining the  usual image function and adding a legend
>> # first change margin for some more room
>> nr <- 100
>> ramp <- colorRamp(c("blue", "green"))
>> kleur <- rgb( ramp(seq(0, 1, length = nr)), max = 255)
>> par( mar=c(5,5,5,8), col.axis =1)
>> image(GRID, col=kleur, axes=T)
>> plot(shape,add =TRUE , border = "red", axes=F, las=1)
>> image.plot( zlim=c(min(data["ndvi"]),max(data["ndvi"])),
>> nlevel=nr,legend.only=TRUE, horizontal=F, col=kleur)
>> box()
>>
>>
>>
>>     
>
>




More information about the R-sig-Geo mailing list