[R] specify breaks in divergent palette in RColorBrewer: was divergent colors around zero in levelplot()

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Tue Nov 26 09:25:14 CET 2013


On Tue, Nov 26, 2013 at 1:02 AM, C. Alina Cansler <acansler at uw.edu> wrote:
> Don,
>
> This looks helpful:
> https://stat.ethz.ch/pipermail/r-help/2011-March/272361.html

Yes, he's a helpful chap.

 The fundamental problem here is the colour palette. When I was a boy
all we had was a pen plotter with four coloured pens, and of course
you could stick different coloured pens in the different pen slots and
draw four different coloured lines. So your graphics package just said
which number pen it was going to use and the colour that came out was
up to you. Most R graphics functions still have this concept, although
there may be over 100 pens and you don't end up swearing when one runs
out of ink. A numeric value is converted to an integer and the integer
does a lookup in a palette to get the colour.

 What you really want, and what my colourscheme package did, was to
create functions that let users map values directly to colours. You
could then plot points and lines using that function which meant
totally controlled value-to-colour mappings that could be used across
different plots if desired. That worked because points and lines lets
you specify a colour value directly using something like col="#FF23EC"
(as well as allowing col=23 and doing a palette lookup).

 But the image function (and probably levelplot) doesn't allow that so
there's various tricks to make functional colour lookups work. I would
convert the image matrix values to a matrix of colours, then create a
matrix of the values 1:(n*m), and then image() that 1:(n*m) matrix
using the colour matrix as a palette. That way each cell had its own
palette entry, and you controlled that colour using the value-colour
function.

 Or you could just use ggplot which I'm pretty sure has the same
concept of mapping values to colours.

Barry



More information about the R-help mailing list