[R] specify breaks in divergent palette in RColorBrewer: was divergent colors around zero in levelplot()
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Nov 26 10:58:42 CET 2013
On 26/11/2013 08:25, Barry Rowlingson wrote:
> On Tue, Nov 26, 2013 at 1:02 AM, C. Alina Cansler <acansler at uw.edu> wrote:
>> This looks helpful:
> 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
Mis-information alert! The help says
col: a list of colors such as that generated by ‘rainbow’,
‘heat.colors’, ‘topo.colors’, ‘terrain.colors’ or similar
and look at what they generate. Or see e.g. ?col2rgb .
Although base graphics has the concept of a palette of colours, AFAIK it
has always been bolted on top of a general colour specification,
originally RGB and for many years already RGBA.
> 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
> Or you could just use ggplot which I'm pretty sure has the same
> concept of mapping values to colours.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help