rrasterr-rasterrastervis

Modify existing R Color Brewer palette


library(raster); library(rasterVis); library(RColorBrewer)

I want to change the 'Brown Green' theme so that the middle break (140 to 160) is gray. Is that possible?

Here's an example with the volcano data set.

breaks <- c(100, 120, 140, 160, 180, 195) # manual breaks
mapTheme <- rasterTheme(region=brewer.pal(6,"BrBG"))
levelplot(volcano, at=breaks, par.settings=mapTheme)

raster plot


Solution

  • We can prepare a color palette first and replace the third one to be grey, and then put it to the region argument.

    library(raster)
    library(rasterVis)
    library(RColorBrewer)
    
    breaks <- c(100, 120, 140, 160, 180, 195) # manual breaks
    pal <- brewer.pal(6,"BrBG")
    pal[3] <- "grey"
    mapTheme <- rasterTheme(region = pal)
    levelplot(volcano, at=breaks, par.settings=mapTheme)
    

    enter image description here