<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#333333">
    <p>Simply use the same palette as in the example:</p>
    <tt>library(lattice)</tt><tt><br>
    </tt><tt><br>
    </tt><tt>myPal <- read.table(sep="\t", text="</tt><tt><br>
    </tt><tt>155     29     32    Brown</tt><tt><br>
    </tt><tt>238     36     37    Tomato</tt><tt><br>
    </tt><tt>238     77     34    Tomato</tt><tt><br>
    </tt><tt>250    143     35    Dark orange</tt><tt><br>
    </tt><tt>254    215     24    Gold</tt><tt><br>
    </tt><tt>214    223     47    Bitter lemon</tt><tt><br>
    </tt><tt>188    218    112    Sulu</tt><tt><br>
    </tt><tt>179    179    179    Dark gray</tt><tt><br>
    </tt><tt>124    199    177    Keppel</tt><tt><br>
    </tt><tt>105    202    229    Viking</tt><tt><br>
    </tt><tt>72     156    211    Curious blue</tt><tt><br>
    </tt><tt>69     101    173    Chetwode blue</tt><tt><br>
    </tt><tt>58     86     164    Governor bay</tt><tt><br>
    </tt><tt>58     72     155    Dark slate blue</tt><tt><br>
    </tt><tt>44     46     118    Blue bell")</tt><tt><br>
    </tt><tt><br>
    </tt><tt>myPal <- colorRampPalette(rgb(myPal[, 1:3],
      names=as.character(myPal$V4), maxColorValue=255))</tt><tt><br>
    </tt><tt><br>
    </tt><tt>x <- seq(pi/4, 5 * pi, length.out = 100)</tt><tt><br>
    </tt><tt>y <- seq(pi/4, 5 * pi, length.out = 100)</tt><tt><br>
    </tt><tt>r <- as.vector(sqrt(outer(x^2, y^2, "+")))</tt><tt><br>
    </tt><tt>grid <- expand.grid(x=x, y=y)</tt><tt><br>
    </tt><tt>grid$z <- cos(r^2) * exp(-r/(pi^3))</tt><tt><br>
    </tt><tt>levelplot(z~x*y, grid, cuts=14, col.regions=myPal(15),
      margin=FALSE)</tt><br>
    <br>
    --Mel.<br>
    <br>
    <div class="moz-cite-prefix">On 05/17/2017 01:25 PM, Thiago V. dos
      Santos via R-sig-Geo wrote:<br>
    </div>
    <blockquote
      cite="mid:1249795416.1781620.1495041913673@mail.yahoo.com"
      type="cite">
      <pre wrap="">Dear all,

I am trying to change the color for zero values in a map produced using levelplot to plot a raster file. Specifically, I want to reproduce this figure: <a class="moz-txt-link-freetext" href="http://i.imgur.com/mjXxZhO.png">http://i.imgur.com/mjXxZhO.png</a>, where a red to blue scale is used, but notice that zero values have been replaced by grey.

As an example, let's use an adapted version of the August irradiation code from the rasterVis webpage:

################################
library(raster)
library(ncdf4)
library(rasterVis)

##Solar irradiation data from CMSAF 
old <- setwd(tempdir())
download.file('<a class="moz-txt-link-freetext" href="https://raw.github.com/oscarperpinan/spacetime-vis/master/data/SISmm2008_CMSAF.zip">https://raw.github.com/oscarperpinan/spacetime-vis/master/data/SISmm2008_CMSAF.zip</a>',
'SISmm2008_CMSAF.zip', method='wget')
unzip('SISmm2008_CMSAF.zip')

listFich <- dir(pattern='\\.nc')
stackSIS <- stack(listFich)
stackSIS <- stackSIS * 24 ##from irradiance (W/m2) to irradiation Wh/m2
idx <- seq(as.Date('2008-01-15'), as.Date('2008-12-15'), 'month')

SISmm <- setZ(stackSIS, idx)
names(SISmm) <- month.abb

setwd(old)

# Set color palette
myTheme=rasterTheme(region=brewer.pal('RdBu', n=11))

Aug <- raster(SISmm, 8)
meanAug <- cellStats(Aug, mean)
levelplot(Aug - meanAug, par.settings = myTheme, margin=FALSE)

################################

In the example above, how can I replace the color of "zero values" with grey?
 
Thanks,
 -- Thiago V. dos Santos

PhD student
Land and Atmospheric Science
University of Minnesota

_______________________________________________
R-sig-Geo mailing list
<a class="moz-txt-link-abbreviated" href="mailto:R-sig-Geo@r-project.org">R-sig-Geo@r-project.org</a>
<a class="moz-txt-link-freetext" href="https://stat.ethz.ch/mailman/listinfo/r-sig-geo">https://stat.ethz.ch/mailman/listinfo/r-sig-geo</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>