rr-rasterrastervis

Density plot of raster stack


I would like to realize a density plot of raster stack using the package rasterVis in R-CRAN. I would like to change the colors with which the distribution of my raster values is represented and also add a legend. Is it possible to do these things using this package? I didn't find any examples to do it. Here my example code

require(raster)
require(rasterVis)
slogo <- stack(system.file("external/rlogo.grd", package="raster")) 
densityplot(slogo,col=c("orange","skyblue1","cyan"))

Solution

  • Most of the rasterVis functions are based on the lattice package. Thus, you should use the par.settings argument providing your preferred theme. Here you will find more information about lattice themes.

    Regarding your question, try this code:

    library(rasterVis)
    f <- system.file("external/test.grd", package="raster")
    r <- raster(f)
    s <- stack(r, r+500, r-500)
    densityplot(s, par.settings = theEconomist.theme)
    

    densityplot with Economist theme