Using the rasterVis package in R

The raster package is great but there is another package, the rasterVis, that allow nice plotting functionalities. The official website maintain by the creator is a really good place to start:, the first part of the code is taken from it and then I will explore some basic tuning available. This package builds on the Lattice ( vocabulary and extend it for raster objects. The data used here can be downloaded from here and here

# load the libraries and the data (code taken from the rasterVis homepage)
## Loading required package: sp
## raster 2.0-41 (21-December-2012)
## Loading required package: lattice
## Loading required package: latticeExtra
## Loading required package: RColorBrewer
## Loading required package: hexbin
## Loading required package: grid
SISmm <- stack("/home/lionel/Bureau/SIS/", 
    "/home/lionel/Bureau/SIS/", "/home/lionel/Bureau/SIS/")  #insert here the path to the files
## Loading required package: ncdf
SISmm <- SISmm * 24  ##from irradiance (W/m2) to irradiation Wh/m2

names(SISmm) <- c("January", "February", "March")

Let's plunge into the possibilities

# standard plot
levelplot(SISmm, layer = 1)

plot of chunk unnamed-chunk-2

# change some standard settings, the 'layer' argument control the layer
# plotted, the 'par.settings' the color of the plot and the 'layout'
# control the arrangement of the panels
levelplot(SISmm, layer = 1:3, par.settings = "RdBuTheme", layout = c(3, 1, 1))

plot of chunk unnamed-chunk-3

The colors can be set using the rasterTheme command and the brewer.pal palette, the different palette can be seen here:

# setting your own colors
mytheme <- rasterTheme(region = brewer.pal(9, "YlGn"))
# load the spanish data
# mask the data
SISmm <- mask(SISmm, gadm)
## Found 1 region(s) and 187 polygon(s)
# plotting with the user defined palette and adding the border of spain
# and putting the color key below
levelplot(SISmm, layer = 1:3, par.settings = mytheme, margin = FALSE, main = "Spain irradiation in\n January-February-March", 
    colorkey = list(space = "bottom"), layout = c(3, 1, 1)) + layer(sp.polygons(gadm))

plot of chunk unnamed-chunk-5

There are of course many other possibilities with these functions but this should keep us occupied with nice mapping for a while!