October 29, 2023


Last week we learned about vector data as a means to representing discrete spatial data. For example, if you have a polygon showing the boundary of Middlesex County, any point inside that polygon is in the county, and points outside are not. But there is also spatial information that is continuous across space. For example, something like elevation will vary continuously across Middlesex county (or anywhere else, for that matter).

However, because these values can be measured at any location, the differences between locations could be infinitely small, making it impossible to capture all the possible variability in a single dataset. A raster instead measures these variables at regular intervals (e.g., every square meter), and these values are expressed as a regular grid over an area of interest. This won’t capture all the potential variation, but provides a good approximation of how the values change over a given space.

Individual rasters typically store one variable (although these can be combined into a multilayer raster or raster stack). Rasters are used to represent lots of different kinds of environmental data, but have become particularly important as more and more data are accumulated using satellites and other aerial sensing. For example, spectroradiometers mounted on satellites can be used to measure sea surface temperatures at regular intervals, which are then assembled into a raster of values covering the earth’s oceans. Satellite images of the surface of the earth are simply rasters that store color/hue values, which can then be translated to pixels in a digital image.

In this lab, we’ll look at working with raster data in R using the terra package. This package was developed to make working with rasters more straightforward, and to better handle the large amounts of data contained in a raster. We’ll also make use of another package called tidyterra, which makes it easier to use terra objects with tidyverse packages like The combination of these two packages will enable us to incorporate raster data into our work in similar ways to other data types we’ve encountered so far.

To get started, make sure to load the following packages: