Skip to content

Natural colours for topographic data

6 messages · Karl Ove Hufthammer, David Winsemius, Barry Rowlingson +1 more

#
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.
#
On Nov 23, 2009, at 11:52 AM, Karl Ove Hufthammer wrote:

            
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.
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
#
On Mon, 23 Nov 2009 12:21:03 -0500 David Winsemius
<dwinsemius at comcast.net> wrote:
Thanks for the suggestion, but the arguments that 'color.scale' takes 
(range of red, green and blue values) makes it not very useful for this 
purpose.
#
On Tue, Nov 24, 2009 at 8:42 AM, Karl Ove Hufthammer <karl at huftis.org> wrote:
Have you tried my colourscheme package? Its not on CRAN but you can
get it from here:

http://r-forge.r-project.org/projects/colourscheme/

And can be installed thus:
 > install.packages("colourschemes",repos="http://r-forge.r-project.org")

 [sorry about the inconsistency between 'colourscheme' and 'colourschemes'!]

Vignette via r-forge's source code browser:
http://r-forge.r-project.org/plugins/scmsvn/viewcvs.php/*checkout*/pkg/inst/doc/colourschemes.pdf?rev=19&root=colourscheme

 It defines various ways of mapping values to colours and using those
colours in plots. I use topographic-style colour schemes in the
examples, so this might be just what you want. The example in
?multiRamp is this:

# topological colour scheme - water, land, ice:
     tramp = multiRamp(rbind(c(-2000,0),c(0,1000),c(1000,9000)),
      list(c("black","blue"),c("green","brown"),c("gray70","gray70"))
      )

then:

 > tramp(-100)
 [1] "#0000F2FF"

 - is  a colour between black and blue in the ocean
[1] "#539515FF"

 - is somewhere between green and brown in the land

 > tramp(1500)
 [1] "#B3B3B3FF"

 - is the gray of the ice.

No logarithmic colour scaling, but I do detail in the vignette how to
write your own colour scheme functions that are compatible with the
ones supplied. Will be glad to help more on this!

Barry
#
On 11/24/2009 07:42 PM, Karl Ove Hufthammer wrote:
Hi Karl,
For a start, you could try:

color.scale(oceandepths,extremes=c("lightblue","blue"))

for the water and

color.scale(vegetationcover,c(0.55,0),0.55,0)

for the land as really basic "natural" colors. There are several ways to 
specify the value to color transformations, and you can even overwrite 
some parts of the color matrix using logical vectors, like coloring 
everything over 4000 meters white for snow.

Jim
1 day later
#
Tysdag 24. november 2009 11.08.08 skreiv du:
Thanks for the suggestion. It looks very nice. Perhaps I?ll even write a 
general function for generating topographic colour scales, based on this.
(It might be a while before it?s ready, though.)