R Spatial Ecosystem

Timothée Giraud

Feb 28, 2025

A bit of history

  • before 2003: spatial, sgeostat, splancs, akima, geoR, spatstat, spdep, maptools.
  • 2003: rgdal (Bivand et al., 2023), interface between R and GDAL and PROJ4
  • 2005: sp (Pebesma, 2018), classes and methods for spatial objects, quickly adopted.
  • 2008: sp support in ggplot2
  • 2010: rgeos (Bivand and Rundel, 2023), interface between R & GEOS.
  • 2010: raster (Hijmans, 2023a), support for raster data
  • 2016: sf (Pebesma, 2018), replace sp, rgdal & rgeos
  • 2020: terra (Hijmans, 2023b), replace raster

Spatial data

Raster

An image located in space.

Geographic information is stored in pixels.

Each pixel, defined by a resolution, has value(s) that can be processed and mapped.

Spatial data

Vector

Geometric objects such as points, lines or polygons.

These vector objects do not pixelate.

Each object has a unique identifier.

Vector and Raster

Lambert and Zanin (2016)

Ecosystem foundations

Widely used geographic libraries:

Pebesma and Bivand (2023, chap. 1.7)

These are external dependencies

  • Installation
  • Reproducibility

Consider containerization (Nüst and Pebesma, 2021).

sf package

Published in 2016 by Edzer Pebesma.

© Allison Horst, 2018

Main features

  • import / export
  • display
  • geoprocessing
  • support for unprojected data (on the globe)
  • use of the simple feature standard
  • compatibility with the pipe operators (|> or %>%)
  • compatibility with tidyverse operators.

terra package

The terra package lets you manage vector data and, above all, raster.

Main features

  • Viewing
  • Study area modifications (projection, crop, mask, aggregation, merge, etc.)
  • Spatial algebra (local, focal, global, zonal operations)
  • Transformation and conversion (rasterization, vectorization)

Thematic Cartography


ggplot2 + ggspatial (Dunnington, 2023)


mapsf (Giraud, 2022)

Interactive maps

Interactive maps

library(mapview)
mapview(mtq)

Interactive maps with shiny

rcarto.shinyapps.io/cityguess

Color palettes

Numerous palettes are available directly in R-base, and almost 70 (!) packages offer palettes.

hcl.colors()

cols4all::c4a_gui()

Spatial analysis / spatial statistics

  • spatstat : Point pattern analysis
  • gstat : Variograms and Krigeage
  • rgeoda : Geoda with R
  • GWmodel, spgwr : Geographically Weighted Models
  • Spatial sampling
  • Point pattern analysis
  • Geostatistics
  • Disease mapping and areal data analysis
  • Spatial regression
  • Ecological analysis

Spatial datasets

Admin :
rnaturalearth giscoR
tigris, mapSpain, geobr

Climat :
geodata

Elevations :
elevatr

Eco / Socio / Demo datasets :
wbstats (World Bank)
eurostat
rdhs (health)

Satellite imagery :
sen2r (Sentinel-2)
MODIStsp (MODIS)
rgee (Google Earth Engine)
nasapower (meteo, climato)

Bibliography

Appelhans, T., Detsch, F., Reudenbach, C. and Woellauer, S. (2022). Mapview: Interactive viewing of spatial data in r. https://CRAN.R-project.org/package=mapview
Bivand, R., Keitt, T. and Rowlingson, B. (2023). Rgdal: Bindings for the ’geospatial’ data abstraction library. https://CRAN.R-project.org/package=rgdal
Bivand, R. and Rundel, C. (2023). Rgeos: Interface to geometry engine - open source (’GEOS’). https://CRAN.R-project.org/package=rgeos
Cheng, J., Karambelkar, B. and Xie, Y. (2023). Leaflet: Create interactive web maps with the JavaScript ’leaflet’ library. https://CRAN.R-project.org/package=leaflet
Cooley, D. (2020). Mapdeck: Interactive maps using ’mapbox GL JS’ and ’deck.gl’. https://CRAN.R-project.org/package=mapdeck
Dunnington, D. (2023). Ggspatial: Spatial data framework for ggplot2. https://CRAN.R-project.org/package=ggspatial
GDAL/OGR contributors. (2022). GDAL/OGR geospatial data abstraction software library. Open Source Geospatial Foundation. https://doi.org/10.5281/zenodo.5884351
GEOS contributors. (2021). GEOS coordinate transformation software library. Open Source Geospatial Foundation. https://libgeos.org/
Giraud, T. (2022). Mapsf: Thematic cartography. https://CRAN.R-project.org/package=mapsf
Hijmans, R. J. (2023a). Raster: Geographic data analysis and modeling. https://CRAN.R-project.org/package=raster
Hijmans, R. J. (2023b). Terra: Spatial data analysis. https://CRAN.R-project.org/package=terra
Hvitfeldt, E. (2021). Paletteer: Comprehensive collection of color palettes. https://github.com/EmilHvitfeldt/paletteer
Lambert, N. and Zanin, C. (2016). Manuel de cartographie: Principes, méthodes, applications. Armand Colin.
Nüst, D. and Pebesma, E. (2021). Practical reproducibility in geography and geosciences. Annals of the American Association of Geographers, 111(5), 1300–1310. https://doi.org/10.1080/24694452.2020.1806028
Pebesma, E. (2018). Simple Features for R: Standardized Support for Spatial Vector Data. The R Journal, 10(1), 439–446. https://doi.org/10.32614/RJ-2018-009
Pebesma, E. and Bivand, R. (2023). Spatial Data Science: With applications in R (p. 352). Chapman and Hall/CRC. https://r-spatial.org/book/
PROJ contributors. (2021). PROJ coordinate transformation software library. Open Source Geospatial Foundation. https://proj.org/
Tennekes, M. (2018). tmap: Thematic maps in R. Journal of Statistical Software, 84(6), 1–39. https://doi.org/10.18637/jss.v084.i06
Tennekes, M. (2023). cols4all: Colors for all. https://CRAN.R-project.org/package=cols4all