Simply use the same palette as in the example: library(lattice)myPal <- read.table(sep="\t", text=" 155 29 32 Brown 238 36 37 Tomato 238 77 34 Tomato 250 143 35 Dark orange 254 215 24 Gold 214 223 47 Bitter lemon 188 218 112 Sulu 179 179 179 Dark gray 124 199 177 Keppel 105 202 229 Viking 72 156 211 Curious blue 69 101 173 Chetwode blue 58 86 164 Governor bay 58 72 155 Dark slate blue 44 46 118 Blue bell") myPal <- colorRampPalette(rgb(myPal[, 1:3], names=as.character(myPal$V4), maxColorValue=255)) x <- seq(pi/4, 5 * pi, length.out = 100) y <- seq(pi/4, 5 * pi, length.out = 100) r <- as.vector(sqrt(outer(x^2, y^2, "+"))) grid <- expand.grid(x=x, y=y) grid$z <- cos(r^2) * exp(-r/(pi^3)) levelplot(z~x*y, grid, cuts=14, col.regions=myPal(15), margin=FALSE) --Mel. On 05/17/2017 01:25 PM, Thiago V. dos
Santos via R-sig-Geo wrote:
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: http://i.imgur.com/mjXxZhO.png, 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('https://raw.github.com/oscarperpinan/spacetime-vis/master/data/SISmm2008_CMSAF.zip', '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 R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo |
_______________________________________________ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo