Search code examples
rbackground-colorlevelplotrastervis

Change background colour when plotting categorical data in rasterVis using levelplot


I have a categorical data (lulc) for a land use land cover having 6 classes. I am trying to plot this data using levelplot in rasterVis

l<-as.factor(lulc)
rat <- levels(l)[[1]]
rat[["landcover"]] <- c("Agriculture", "Bare land", "Built-up", "Vegetation","Water","Wetland")
levels(lulc) <- rat
levelplot(lulc, col.regions=c("yellow","cyan","pink","green","lightblue","orange"), xlab="", ylab="")

But the study area is coastal. Hence I want to show NAs as ocean represented with "lightblue". I tried panel.background="lightblue", but it does not change anything in the plot. What I get is following; enter image description here

But I want as following; enter image description here


Solution

  • Try

    library(rasterVis)
    f <- system.file("external/test.grd", package="raster")
    r <- raster(f)
    levelplot(r, par.settings=list(panel.background=list(col="skyblue")))