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: http://rastervis.r-forge.r-project.org/, 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 (http://lattice.r-forge.r-project.org/) vocabulary and extend it for raster objects. The data used here can be downloaded from here https://www.box.com/shared/rl51y1t9sldxk54ogd44 and here http://www.filefactory.com/file/3hjj4ew7sdeb/n/ESP_adm0_RData

# load the libraries and the data (code taken from the rasterVis homepage)
library(raster)
## Loading required package: sp
## raster 2.0-41 (21-December-2012)
library(rasterVis)
## 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/SISmm200801010000300UD0024501UD.nc", 
    "/home/lionel/Bureau/SIS/SISmm200802010000300UD0024501UD.nc", "/home/lionel/Bureau/SIS/SISmm200803010000300UD0024501UD.nc")  #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: http://www.datavis.ca/sasmac/brewerpal.html

# setting your own colors
mytheme <- rasterTheme(region = brewer.pal(9, "YlGn"))
# load the spanish data
load("/home/lionel/Bureau/ESP_adm0(1).RData")
# 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!