Spatial Analysis and Mapping with R

Preface

This tutorial introduces the reader to some of the amazing capabilities of R to work with and map geographic data. Geographic data are data that contain spatial attributes (or spatial data) that define a geographic space (location, area, elevation, etc.) and non spatial attributes (f.e., population density, pollutant concentrations, temperature).

This tutorial was developed for one the units of the course “ENVS 420: Research Seminar in Environmental Sciences” offered at the University of Baltimore. However, it is hoped that readers outside of ENVS 420 who are interested in geospatial analysis and with a basic familiarity of R find this tutorial useful.

The use of an integrated developer environment (IDE) or an IDE like configuration such as the IDE RStudio (https://rstudio.com/) or the Nvim-R plug-in for the integration of vim/neovim and R (https://github.com/ jalvesaq/Nvim-R/tree/stable) is recommended but not necessary.

The tutorial was written with RMarkdown (v. 2.6) (Allaire et al., 2020; Xie et al., 2018, 2020) in R (v. 4.0.2) (R Core Team, 2020).

Required R packages:

  • dplyr (Wickham et al., 2020)
  • openxlsx (Schauberger & Walker, 2020)
  • RColorBrewer (Neuwirth, 2014)
  • sf (Pebesma, 2018)
  • tmap (Tennekes, 2018)
  • tidyr (Wickham et al., 2020)

Data

Datatasets used are archived in a zip compressed file (SpatialAnalysisData.zip) that can be downloaded at SpatialAnalysisData. The link will connect you to a cloud storage service (MEGA, https://mega.nz) and ask you to download the file. By accessing the cloud storage service and downloading the file/data you agree to the terms of service of MEGA and to the terms of use of the code and data.

References

Allaire, J., Xie, Y., McPherson, J., Luraschi, J., Ushey, K., Atkins, A., Wickham, H., Cheng, J., Chang, W., & Iannone, R. (2020). rmarkdown: Dynamic Documents for R. https://github.com/rstudio/rmarkdown

Neuwirth, E. (2014). RColorBrewer: ColorBrewer Paletteshttps://CRAN.R-project.org/package=RColorBrewer

Pebesma, E. (2018). Simple Features for R: Standardized Support for Spatial Vector Data. The R Journal, 10(1), 439–446. doi: 10.32614/RJ-2018-009

R Core Team. (2020). R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing. https://www.R-project.org/

Schauberger, P., & Walker, A. (2020). openxlsx: Read, Write and Edit xlsx Files. https://CRAN.R-project.org/package=openxlsx

Tennekes, M. (2018). tmap: Thematic maps in R. Journal of Statistical Software84(6), 1–39. doi: 10.18637/ jss.v084.i06

Wickham, H., François, R., Henry, L., & Müller, K. (2020). dplyr: A Grammar of Data Manipulation. https://CRAN.R-project.org/package=dplyr
Wickham, H., & Henry, L. (2020). tidyr: Tidy Messy Datahttps://CRAN.R-project.org/package=tidyr
Xie, Y., Allaire, J. J., & Grolemund, G. (2018). R Markdown: The definitive guide. Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown
Xie, Y., Dervieux, C., & Riederer, E. (2020). R Markdown Cookbook. Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown-cookbook

 

 

Cover image:  Land Use in Greater Baltimore (2002).
Data source:  Maryland Archived Land Use Land Cover 2002, Maryland Department of Planning,  online at https://data.imap.maryland.gov/datasets/96116be90edb4e8d933048f345c3a487?geometry=-79.386%2
C38.060%2C-75.096%2C39.558#www.mdp.state.md.us/OurWork/landuse.shtml
.  Accessed on April 17, 2021.

License

Icon for the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License

Spatial Analysis and Mapping with R: A Short Tutorial Copyright © 2021 by Wolf T. Pecher is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License, except where otherwise noted.