[R] Natural colours for topographic data

David Winsemius dwinsemius at comcast.net
Mon Nov 23 18:21:03 CET 2009


On Nov 23, 2009, at 11:52 AM, Karl Ove Hufthammer wrote:

> Dear list members
>
> I'm currently working on some topographic (elevation) data, and was
> somewhat surprised that the 'topo.colors' and 'terrain.colors' are of
> little to no use here.
>
> The problem is that these functions only return a palette of colours;
> they don't map depth values to colours. So if I plot (using 'image',
> 'persp' or similar functions) and specify these palettes, ocean areas
> may coloured green (indicating) land, which may be quite confusing.
>
> I have looked through various packages, and have found several colour
> palette functions, but none that do what I need.
>
> Basically, I just need a function that takes a vector of elevation
> values as input, and outputs a vector of 'natural' colours. For  
> negative
> values (i.e., ocean), the 'blue' colours of 'topo.colors' would be OK,
> and for positive values either the colours of 'terrain.colors' or the
> non-blue colours of 'topo.colors' would look nice.
>
> It is of course not very difficult to create such a function myself,
> e.g. using the 'cut' function and a standard palette. But perhaps
> somebody has already has made one?
>
> My ideal topographic colour mapping function would support separate
> colour levels for water and land (so that you can specifiy for  
> example 5
> colours of water, from a depth of 5000 meters to 0 meters, and 20
> colours of land, from a depth of 0 meters to 2000 meters), support
> several nice palettes, and also support logarithmic colour mapping.  
> But
> I would be happy with a simple one, that just mapped negative values  
> to
> water colours and positive values to land colours.

Searching with the strategy "color positive negative zero" in r-search  
and limiting it to r-help replies,  I get this Jim Lemon reply using  
(naturally) plotrix's color.scale:

http://finzi.psych.upenn.edu/R/Rhelp02/archive/90837.html

The application to your needs looks pretty immediate.


>
> -- 
> Karl Ove Hufthammer
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list