[Rd] Colour Schemes

Richard.Cotton at hsl.gov.uk Richard.Cotton at hsl.gov.uk
Thu May 21 15:18:04 CEST 2009


> I've been thinking hard about generating colour schemes for data.
> There's quite a bit of existing code scattered in various packages for
> playing with colours and colour palettes, but I can't find the sort of
> thing I'm after for applying colours to data...
> 
> To my mind a colour scheme is a mapping from data values to colours.
> There's a multitude of such mappings depending on the nature of the
> data. For example, for a factor you might want to map levels to unique
> colours. For numbers that run from -4 to +2 you might want to use a
> diverging colour palette centred on zero. This might be continuous in
> some colour space or composed of a small number of discrete colours,
> each of which covers a range of values. Or it could be piecewise
> continuous as used in topographic maps - less than zero is blue, zero
> to 400 goes from sandy yellow to grassy green, 400 to 1000 goes from
> grassy green to rocky brown, then suddenly you hit the ice and 1000
> and upwards is white.  Or you could have a multivariate mapping where
> (x,y,z) -> (r,g,b,a) in complex and non-linear ways.
> 
> I see a set of factory functions that return colour scheme mapping
> functions that map data to colours, so you'd do:
> 
>  # unique colour for each factor level
>  scheme1 = exactColours(data$f,someColours)  # data$f is a factor,
> someColours is a vector of colour values
>  plot(data$x,data$y,col=scheme1(data$f))
> 
>  # topological map colouring
>  scheme2 = continuousColours(list(-1000,"blue",0,"sandYellow",
> 400,"grassGreen",1000,"rockBrown",1000,"white",10000))
> # or something...
>  plot(data$x,data$y,col=scheme2(data$height))
> 
> Now just because I can't find existing functions like this doesn't
> mean they don't exist. There's stuff in plotrix, colorspace,
> RColorBrewer etc for creating palettes but then the user is left to
> their own devices to map colours to data values.
> 
>  Does this kind of thing sound useful? Has it been done? Is it worth
> doing? Anybody got any better ideas?

Most of the plots where colour is typically used to signify a variable 
already do map colours to data values.  Take a look at help pages for 
levelplot/contourplot/wireframe from the lattice package, and image from 
base graphics.

(The format is typically slightly different to your suggested 
specification, though the principle is the same.  The functions take a 
vector of cut points, and a vector of colours.)

There may be some utility in creating functions to generate these colour 
maps outside of the plotting functions, if only so that the code can be 
recycled for new functions.

Regards,
Richie.

Mathematical Sciences Unit
HSL



------------------------------------------------------------------------
ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}



More information about the R-devel mailing list