Skip to content

Spatial visualization

Jose M. Gutierrez edited this page Oct 18, 2018 · 12 revisions

Function spatialPlot is a wrapper for the lattice (trellis) plot methods for spatial data in sp::spplot. Therefore, many different aspects of the map can be controlled passing the relevant arguments to spplot. Fine control of graphical parameters for the trellis display can be also controlled using trellis.par.set from package lattice.

Additionally, includes its own parameters:

  • backdrop.theme: Easy layout of world terrestial limits (coastline or countries).
  • set.min and set.max: Options to preserve adequate ranges for map representation, avoiding the influence of extreme values. Note that this is different than setting a range of values with an interval using the at argument.
  • lonCenter: Choose the longitude of the map center.

spatialPlot is built for climatological grids, i.e. for grids with a single time value. Function climatology from package transformeR is recommended to compute the desired aggregation function over the time dimension. Next, we compute the climatic mean (default in climatology) to each member of a multimember grid (CFS_Iberia_tas) to apply spatialPlot. As a result a multipanel plot is obtained.

data("CFS_Iberia_tas")
# Climatology is computed:
clim <- climatology(CFS_Iberia_tas, by.member = TRUE)
spatialPlot(clim)

Using optional arguments:

spatialPlot(clim, backdrop.theme = "coastline", set.min = 5, set.max = 14)

Further arguments can be passed to 'spplot'...

# ... a subset of members to be displayed, using 'zcol':
spatialPlot(clim,
                backdrop.theme = "coastline",
                zcol = 1:4)

# ... regional focuses (e.g. the Iberian Peninsula).
spatialPlot(clim,
                backdrop.theme = "countries",
                xlim = c(-10,5), ylim = c(35,44),
                zcol = 1:4,
                scales = list(draw = TRUE))

# Changing the default color palette and ranges:
spatialPlot(clim,
                backdrop.theme = "coastline",
                zcol = 1:4,
                col.regions = cm.colors(27), at = seq(10,37,1))

For ensemble means climatology should be called with 'by.member' set to FALSE:

clim <- climatology(CFS_Iberia_tas, by.member = FALSE)

Adding contours to the plot is direct with argument 'contour':

spatialPlot(clim,
                scales = list(draw = TRUE),
                contour = TRUE,
                main = "tas Predictions July Ensemble Mean")

Multigrids can also be plotted:

data("NCEP_Iberia_psl")
## Winter data are split into monthly climatologies
monthly.clim.grids <- lapply(getSeason(NCEP_Iberia_psl), function(x) {
      climatology(subsetGrid(NCEP_Iberia_psl, season = x))
})

## Skip the temporal checks, as grids correspond to different time slices
mg <- do.call("makeMultiGrid",
              c(monthly.clim.grids, skip.temporal.check = TRUE))
              ## We change the panel names
spatialPlot(mg,
                backdrop.theme = "coastline",
                names.attr = c("DEC","JAN","FEB"),
                main = "Mean PSL climatology 1991-2010",
                scales = list(draw = TRUE))

Station data is also allowed:

# Station data:
data("VALUE_Iberia_pr")
spatialPlot(climatology(VALUE_Iberia_pr), 
             colorkey = TRUE, 
             backdrop.theme = "countries")

Overlay point data over gridded plots

SpatialPlot uses spplot (package sp), therefore, you could convert your station data into a SpatialPoints* object and use argument sp.layout like this in order to obtain gridded and station overlaid graphs:

library(sp)
sp <- SpatialPoints(getCoordinates(VALUE_Iberia_pr))
spatialPlot(climatology(EOBS_Iberia_pr), sp.layout = list(sp, first = FALSE, pch = 2, col = "black"))