[R] colour palette for positive/negative range
Barry Rowlingson
b.rowlingson at lancaster.ac.uk
Fri Mar 18 16:45:53 CET 2011
On Fri, Mar 18, 2011 at 3:37 PM, Frank Schwach <fs5 at sanger.ac.uk> wrote:
> Hi,
>
> I'm plotting a heatmap with values ranging from -10 to +10 and I would
> like the negative values to show up in shades of blue and the positive
> ones in shadea of red. Basically, I want exactly what the RColorBrewer
> palette RdBu does but with more of a gradual change (the RdBu can only
> give me 11 distinct colours). Any suggestions?
Use RColorBrewer along with my colourscheme package
[https://r-forge.r-project.org/R/?group_id=435] to interpolate between
them:
library(RColorBrewer)
bp = brewer.pal(11,"RdBu")
library(colourschemes)
cs = rampInterpolate(c(-10,10),bp)
now cs is a function that interpolates the 11 palette colours so you
have a continuous colour palette. Note the interpolation is (umm I
think) linear in R G and B.
s=seq(-10,10,len=100
plot(s,s,col=cs(s),pch=19)
gives you 100 different colours.
Barry
More information about the R-help
mailing list