Re: [R] color of opposite sign values in filled.contour

From: Duncan Murdoch <>
Date: Fri 05 Jan 2007 - 14:46:00 GMT

On 1/5/2007 9:08 AM, Claudia Tebaldi wrote:
> Dear all,
> especially those of you that kindly provided suggestions yesterday,
> I was not asking for cool palettes -- even if I now appreciate the
> pointers -- but I was asking for a way to make the 0 level of a filled
> contour plot correspond to the neutral color in the color scale
> when the range of my values is not symmetrical around zero...without
> hacking into the filled.contour function (which I'm not able to do
> succesfully). I couldn't get the ggplot package suggested because I'm not
> running MAC OSX 10.4, unfortunately...all the other suggestions didn't
> provide a way least that I could recognize.
> Thanks again -- last time I bother you I promise!

The easiest way would be to use the "levels" parameter to create breakpoints which aren't linear in the original scale. For example,

x <- y <- seq(-10,10,len=20)
z <- outer(x, y, function(x,y) x^2+y^2)
filled.contour(x,y,z, levels=seq(0,15)^2)

If you don't want to transform the spacing between the colors, you just want to change the sequence you get, then you should write your own palette function. For example,

mypalette <- function(n) {

   n1 <- n %/% 3
   n2 <- n - n1 + 1
   c( colorRampPalette(c("red", "white"))(n1),

      colorRampPalette(c("white", "blue"))(n2)[-1] ) }

filled.contour(x,y,z, color=mypalette)

Duncan Murdoch mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Sat Jan 06 02:00:20 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 05 Jan 2007 - 16:30:26 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.