[R-sig-Geo] Image colours based on certain values

Roger Bivand Roger.Bivand at nhh.no
Mon Sep 3 21:29:18 CEST 2007


On Mon, 3 Sep 2007, Michal Gallay wrote:

> Dear R Spatial Users,
>
> I have many DEM ASCII grid files and have produced maps(images) via
> image(). The maps display e.g. slope angle, profile curvature for one area,
> but calculated via different methods.
>
> I have searched R help, the R group, but I couldn't find out how to make R
> use certain colours for certain image values, in order to be able to
> compare the maps, for instance to have the same color for 0 curvature
> values, no matter what is the range of values.
>
> If it helps, the following is applied in a 'for' loop for 20 files:
>
> raster.values <- read.asciigrid(fname=Files[i], as.image = FALSE,
>                          plot.image = FALSE, colname = Files[i])
>
> min.val <- min(raster.values at data, na.rm=TRUE)
> max.val <- max(raster.values at data, na.rm=TRUE)
>
> image(raster.values, zlim=c(min.val,max.val), col=bpy.colors(255,
> cutoff.tails = 0.1), axes=TRUE)

Set breaks= explicity, it will be passed through to image.default(); 
perhaps do not set zlim=, and note that there should be one more break 
than the number of colours.

Roger

>
> I appreciate and thank you for help.
>
> Michal
>
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, 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