<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#333333">
<p>You might need to try different values for the number of legend
breaks depending on your dataset (e.g. `cuts=13,
col.regions=myPal(14)`) and/or use argument `at=seq(-1, 1, .1)` to
manually define breaks. Refer to ?levelplot() documentation.<br>
</p>
<br>
<div class="moz-cite-prefix">On 05/18/2017 12:27 PM, Thiago V. dos
Santos wrote:<br>
</div>
<blockquote
cite="mid:1571909681.837951.1495124832162@mail.yahoo.com"
type="cite">
<div style="color:#000; background-color:#fff;
font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande,
sans-serif;font-size:13px">
<div id="yui_3_16_0_ym19_1_1495120534235_26928"><span>Hi Mel,</span></div>
<div id="yui_3_16_0_ym19_1_1495120534235_26931"><span><br>
</span></div>
<div id="yui_3_16_0_ym19_1_1495120534235_26927"><span
id="yui_3_16_0_ym19_1_1495120534235_26964">Thank you ver
much for the suggestion. I've reproduced your palette, which
looks like exactly what I was looking for. However, the grey
color is still not associated to zero values in the map.</span></div>
<div id="yui_3_16_0_ym19_1_1495120534235_26927"><span><br>
</span></div>
<div id="yui_3_16_0_ym19_1_1495120534235_26927" dir="ltr"><span>After
plotting my raster with your palette as an argument:</span></div>
<div id="yui_3_16_0_ym19_1_1495120534235_26927" dir="ltr"><span><br>
</span></div>
<div id="yui_3_16_0_ym19_1_1495120534235_26927" dir="ltr"><span>levelplot(annual.mask,
cuts=14, col.regions=myPal(15), margin=F)<br>
</span></div>
<div id="yui_3_16_0_ym19_1_1495120534235_26927" dir="ltr"><span><br>
</span></div>
<div id="yui_3_16_0_ym19_1_1495120534235_26927" dir="ltr"><span
id="yui_3_16_0_ym19_1_1495120534235_30562">I ended up with a
figure like this: </span><a moz-do-not-send="true"
href="http://i.imgur.com/aqZkCGZ.png">http://i.imgur.com/aqZkCGZ.png</a>,
where I was hoping to have all white (i.e. zero values) in the
map filled with grey.</div>
<div id="yui_3_16_0_ym19_1_1495120534235_26927" dir="ltr"><br>
</div>
<div id="yui_3_16_0_ym19_1_1495120534235_26927" dir="ltr">Any
other ideas to achieve that?</div>
<div id="yui_3_16_0_ym19_1_1495120534235_26927" dir="ltr"><br>
</div>
<div id="yui_3_16_0_ym19_1_1495120534235_26927" dir="ltr">This
is the file and code to reproduce the figure:</div>
<div id="yui_3_16_0_ym19_1_1495120534235_26927" dir="ltr"><br>
</div>
<div id="yui_3_16_0_ym19_1_1495120534235_26927" dir="ltr"><a
moz-do-not-send="true"
href="https://dl.dropboxusercontent.com/content_link/jnv58wx0QN8ObKaiqigVckXtDmanOVYlgBxXoiym4oty5MS93xHolItNZ8tJ5gVF/file?dl=1"
id="yui_3_16_0_ym19_1_1495120534235_41521">https://dl.dropboxusercontent.com/content_link/jnv58wx0QN8ObKaiqigVckXtDmanOVYlgBxXoiym4oty5MS93xHolItNZ8tJ5gVF/file?dl=1</a><br>
</div>
<div id="yui_3_16_0_ym19_1_1495120534235_26927" dir="ltr">########################</div>
<div dir="ltr" id="yui_3_16_0_ym19_1_1495120534235_37851">library(rasterVis)</div>
<div dir="ltr" id="yui_3_16_0_ym19_1_1495120534235_37852"><br
id="yui_3_16_0_ym19_1_1495120534235_37853">
</div>
<div dir="ltr" id="yui_3_16_0_ym19_1_1495120534235_37854">myPal
<- read.table(sep=",", text="</div>
<div dir="ltr" id="yui_3_16_0_ym19_1_1495120534235_37855">155,29,32,Brown</div>
<div dir="ltr" id="yui_3_16_0_ym19_1_1495120534235_37856">238,36,37,Tomato</div>
<div dir="ltr" id="yui_3_16_0_ym19_1_1495120534235_37857">238,77,34,Tomato</div>
<div dir="ltr" id="yui_3_16_0_ym19_1_1495120534235_37858">250,143,35,Dark.orange</div>
<div dir="ltr" id="yui_3_16_0_ym19_1_1495120534235_37859">254,215,24,Gold</div>
<div dir="ltr" id="yui_3_16_0_ym19_1_1495120534235_37860">214,223,47,Bitter.lemon</div>
<div dir="ltr" id="yui_3_16_0_ym19_1_1495120534235_37861">188,218,112,Sulu</div>
<div dir="ltr" id="yui_3_16_0_ym19_1_1495120534235_37862">179,179,179,Dark.gray</div>
<div dir="ltr" id="yui_3_16_0_ym19_1_1495120534235_37863">124,199,177,Keppel</div>
<div dir="ltr" id="yui_3_16_0_ym19_1_1495120534235_37864">105,202,229,Viking</div>
<div dir="ltr" id="yui_3_16_0_ym19_1_1495120534235_37865">72,156,211,Curious.blue</div>
<div dir="ltr" id="yui_3_16_0_ym19_1_1495120534235_37866">69,101,173,Chetwode.blue</div>
<div dir="ltr" id="yui_3_16_0_ym19_1_1495120534235_37867">58,86,164,Governor.bay</div>
<div dir="ltr" id="yui_3_16_0_ym19_1_1495120534235_37868">58,72,155,Dark.slate.blue</div>
<div dir="ltr" id="yui_3_16_0_ym19_1_1495120534235_37869">44,46,118,Blue.bell")</div>
<div dir="ltr" id="yui_3_16_0_ym19_1_1495120534235_37870"><br
id="yui_3_16_0_ym19_1_1495120534235_37871">
</div>
<div dir="ltr" id="yui_3_16_0_ym19_1_1495120534235_37872">myPal
<- colorRampPalette(rgb(myPal[, 1:3],
names=as.character(myPal$V4), maxColorValue=255))</div>
<div dir="ltr" id="yui_3_16_0_ym19_1_1495120534235_37873"><br
id="yui_3_16_0_ym19_1_1495120534235_37874">
</div>
<div dir="ltr" id="yui_3_16_0_ym19_1_1495120534235_37875">r.annual
<- raster("Desktop/r.annual.tif")</div>
<div dir="ltr" id="yui_3_16_0_ym19_1_1495120534235_37876">levelplot(r.annual,
cuts=14, col.regions=myPal(15), margin=F)</div>
<div id="yui_3_16_0_ym19_1_1495120534235_26927" dir="ltr">########################</div>
<div id="yui_3_16_0_ym19_1_1495120534235_26932"> </div>
<div class="signature"
id="yui_3_16_0_ym19_1_1495120534235_26899">Greetings,
<div id="yui_3_16_0_ym19_1_1495120534235_26900"> -- Thiago V.
dos Santos</div>
<div id="yui_3_16_0_ym19_1_1495120534235_26898"><br>
</div>
<div id="yui_3_16_0_ym19_1_1495120534235_26933">PhD student</div>
<div id="yui_3_16_0_ym19_1_1495120534235_26934">Land and
Atmospheric Science</div>
<div id="yui_3_16_0_ym19_1_1495120534235_26935">University of
Minnesota</div>
</div>
<div class="qtdSeparateBR"><br>
<br>
</div>
<div class="yahoo_quoted" style="display: block;">
<div style="font-family: Helvetica Neue, Helvetica, Arial,
Lucida Grande, sans-serif; font-size: 13px;">
<div style="font-family: HelveticaNeue, Helvetica Neue,
Helvetica, Arial, Lucida Grande, sans-serif; font-size:
16px;">
<div dir="ltr"><font face="Arial" size="2"> On Thursday,
May 18, 2017 3:06 AM, Melanie Bacou
<a class="moz-txt-link-rfc2396E" href="mailto:mel@mbacou.com"><mel@mbacou.com></a> wrote:<br>
</font></div>
<br>
<br>
<div class="y_msg_container">
<div id="yiv9549132499">
<div>
<div>Simply use the same palette as in the example:</div>
<tt>library(lattice)</tt><tt><br clear="none">
</tt><tt><br clear="none">
</tt><tt>myPal <- read.table(sep="\t", text="</tt><tt><br
clear="none">
</tt><tt>155 29 32 Brown</tt><tt><br
clear="none">
</tt><tt>238 36 37 Tomato</tt><tt><br
clear="none">
</tt><tt>238 77 34 Tomato</tt><tt><br
clear="none">
</tt><tt>250 143 35 Dark orange</tt><tt><br
clear="none">
</tt><tt>254 215 24 Gold</tt><tt><br
clear="none">
</tt><tt>214 223 47 Bitter lemon</tt><tt><br
clear="none">
</tt><tt>188 218 112 Sulu</tt><tt><br
clear="none">
</tt><tt>179 179 179 Dark gray</tt><tt><br
clear="none">
</tt><tt>124 199 177 Keppel</tt><tt><br
clear="none">
</tt><tt>105 202 229 Viking</tt><tt><br
clear="none">
</tt><tt>72 156 211 Curious blue</tt><tt><br
clear="none">
</tt><tt>69 101 173 Chetwode blue</tt><tt><br
clear="none">
</tt><tt>58 86 164 Governor bay</tt><tt><br
clear="none">
</tt><tt>58 72 155 Dark slate blue</tt><tt><br
clear="none">
</tt><tt>44 46 118 Blue bell")</tt><tt><br
clear="none">
</tt><tt><br clear="none">
</tt><tt>myPal <- colorRampPalette(rgb(myPal[,
1:3], names=as.character(myPal$V4),
maxColorValue=255))</tt><tt><br clear="none">
</tt><tt><br clear="none">
</tt><tt>x <- seq(pi/4, 5 * pi, length.out = 100)</tt><tt><br
clear="none">
</tt><tt>y <- seq(pi/4, 5 * pi, length.out = 100)</tt><tt><br
clear="none">
</tt><tt>r <- as.vector(sqrt(outer(x^2, y^2,
"+")))</tt><tt><br clear="none">
</tt><tt>grid <- expand.grid(x=x, y=y)</tt><tt><br
clear="none">
</tt><tt>grid$z <- cos(r^2) * exp(-r/(pi^3))</tt><tt><br
clear="none">
</tt><tt>levelplot(z~x*y, grid, cuts=14,
col.regions=myPal(15), margin=FALSE)</tt><br
clear="none">
<br clear="none">
--Mel.<br clear="none">
<br clear="none">
<div class="yiv9549132499yqt4846797283"
id="yiv9549132499yqt00828">
<div class="yiv9549132499moz-cite-prefix">On
05/17/2017 01:25 PM, Thiago V. dos Santos via
R-sig-Geo wrote:<br clear="none">
</div>
<blockquote type="cite">
<pre>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 moz-do-not-send="true" rel="nofollow" shape="rect" class="yiv9549132499moz-txt-link-freetext" target="_blank" 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 moz-do-not-send="true" rel="nofollow" shape="rect" class="yiv9549132499moz-txt-link-freetext" target="_blank" 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 moz-do-not-send="true" rel="nofollow" shape="rect" class="yiv9549132499moz-txt-link-abbreviated" ymailto="mailto:R-sig-Geo@r-project.org" target="_blank" href="mailto:R-sig-Geo@r-project.org">R-sig-Geo@r-project.org</a>
<a moz-do-not-send="true" rel="nofollow" shape="rect" class="yiv9549132499moz-txt-link-freetext" target="_blank" href="https://stat.ethz.ch/mailman/listinfo/r-sig-geo">https://stat.ethz.ch/mailman/listinfo/r-sig-geo</a>
</pre>
</blockquote>
</div>
<br clear="none">
</div>
</div>
<br>
<br>
</div>
</div>
</div>
</div>
</div>
</blockquote>
<br>
</body>
</html>