How to reverse the deault color of RasterVis (Levelplot)?

880 views Asked by At

I want to use the deault color of levelplot but in a reverse order. I know how to reverse custom colors but unable to do for default color of rasterVis.rasterVis

library(raster)
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)
levelplot(SISmm)

How do I reverse the color in black indicating higher values and light colors indicating lighter values?

Thank you for any help.

1

There are 1 answers

0
Oscar Perpiñán On BEST ANSWER

rasterTheme is a customization of the custom.theme.2 function of latticeExtra using the magma palette of the `viridisLite package:

     rasterTheme(region = magma(10),
             pch=19, cex=0.7, 
             strip.background = list(col = 'transparent'),
             strip.shingle = list(col = 'transparent'),
             strip.border = list(col = 'transparent'),
             add.lines = list(lwd = .4),
             ...)

Therefore, you should use the region argument with the reversed magma palette:

library(rasterVis)
library(viridisLite)

f <- system.file("external/test.grd", package="raster")
r <- raster(f)

revMagma <- rasterTheme(region = rev(magma(10)))
levelplot(r, par.settings = revMagma)

revMagma