Welcome to TERN Knowledge Base

Raster Values: Graphical Summaries

To explore the cell values of raster layers several types of graphical summaries can be used, such as boxplots, and density plots. Scatter plots can be used to explore the relationships between the values of different raster layers.


Below examples of the generartion graphical summaries of the values and relationships between raster layers in R are presented. These examples are taken from the “Yasi Effects on Green Cover at Mission Beach” tutorial. It can be beneficial to put the code snippets in context by looking at a broader section of the R script. Code snippets have a grey background, and outputs have a white background.

We create boxplots and scatter plots (with loess) using the 'bwplot' and 'splom ' functions in the 'rasterVis' package. To create density plots we use two methods: (1) using the 'densityplot' function in the 'rasterVis' package, and (2) the 'ggplot' function in the 'ggplot2' package. The latter approach produce nicer graphs, but requires more elaborated coding. Finally, we use the 'grid.arrange' function in the 'gridExtra' package to plot multiple grobs (i.e. grid graphical objects) on a page (i.e. in a single graph).

Boxplots and scatter plots

The 'bwplot' and 'splom' functions require a RasterStack or RasterBrick object. In our example we already have a rasterBrick with raw (in %) values (i.e. for 2010-Winter and 2011-Winter). However, we need to create an analogous rasterBrick with standardised (i.e. in SDs) values.

Density plots

Method 1: Using ‘densityplot’ from the ‘rasterVis’ package

Method 2: Using ‘ggplot’ from the ‘ggplot2’ package

To create the the density plot using the 'ggplot' function, we first need to convert the raster cell values to a vector of values (i.e. a variable) using the 'values' function in the 'raster' package. Then we combine all variables into a data frame. Finally, convert the wide format data frame to long format (i.e. combining both year values in the same column with an additional column/variable containing the year-season), as this format is required in the arguments of the 'ggplot' function.

Provide your feedback about the experience with Knowledge base