Spatial-r: Tutorials on spatial data analysis in R

Author
Affiliation

Romain Frelat

Published

November 17, 2025

Introduction

This is a collection of tutorials on how to handle spatial data in . The tutorials target students and scientists in ecology with previous knowledge of the R software.

The core tutorials were developed for a two half-day workshop, but you can follow the tutorials at your own pace.

TipThe ecologist mind

In these tutorials, we characterize the habitat of otters that were observed in 2021 around Montpellier, France. This small toy case study is not relevant ecologically but provides a good opportunity to tackle multiple challenges with handling and collecting spatial data.

Workshop program

Introduction to GIS: vectors vs rasters, coordinate reference system (CRS), and R as a GIS tool

Practice 1 : Vectors (2h)

  • Points: Transform otters field observations as spatial points
  • Lines: Calculate distance from points to nearest lines (river networks)
  • Polygons: Characterize land cover around sites using spatial polygons

Practice 2: Rasters (2h)

  • Raster: Discover what is a raster and get the elevation of field observations
  • Multi-layer: Trace back past monthly climate at the field sites
  • Grid: Transform observations and spatial data into a commun grid

Other tutorials

  • Toy dataset: Get data from GBIF, IGN and CHELSA and create the toy dataset used in this workshop.

R packages

The tutorials rely mostly on the -package terra as it was specifically developed to tackle challenges faced by ecologists or agronomists when doing spatial analysis.
has an exceptional diversity of users and packages, and this is especially true with the dynamic community of -users doing spatial analysis. Another very popular package for handling spatial vector data is sf. The correspondance among terra and sf functions are presented in the vector tutorials.

Other resources

These tutorials were inspired by very valuable online ressources: