Search code examples
rlevelplotrastervis

Specifying color of NA raster values in levelplot (R package rasterVis)


How can I assign a specific color to NA values of a raster when plotting it with the levelplot function from R-package rasterVis? I am searching for a similar functionality as "colNA".


Solution

  • levelplot uses the background color to display the NA values. Thus, you have to modify this color using panel.background.

    library(rasterVis)
    
    myTheme <- BTCTheme()
    myTheme$panel.background$col = 'gray' 
    
    f <- system.file("external/test.grd", package="raster")
    r <- raster(f)
    levelplot(r, par.settings = myTheme)
    

    levelplot with background color