Following on from the previous guide looking at WorldClim data, in this guide I take a look at using RasterStacks to import WorldClim datasets. In the previous guide, we used RasterLayers to import the data, so what is the difference? A RasterStack is a collection of RasterLayers bundled together, or stacked into one object. If you're only dealing with a few RasterLayers, then a RasterStack might not be necessary. However, when the number of RasterLayers increase, it can be easier to work with RasterStacks.
For example, if you wanted to look at minimum, maximum, and mean temperature data, along with precipitation data from WorldClim, using RasterLayers would require you to create 48 separate objects. Using a RasterStack, you could instead create 4 objects containing all the data for each variable.
This guide will also take a look at some of the additional options you have when plotting RasterStacks and other raster objects. Did you know that when you plot a raster object in R using plot()
, it actually invokes the raster::plot
function, while standard objects (e.g. scatterplots) would invoke graphics::plot
? The previous guide suggested you might want to plot a figure which includes separate plots for each month of the year, or you might want a minimum and maximum temperature plot? I'll show you how you can do this easily using RasterStacks and raster::plot
.