This online walkthrough accompanies a 3h “show-and-tell” workshop on making thematic (choropleth) maps in R.

The worked examples demonistrate the quickest routes for getting your data in R and on a map, with a focus on showing how spatial data can be integrated in a familiar tidyverse data-analysis workflow.

The examples demonstrate mainly static maps, but interactive thematic maps are included as well. R packages demonistrated are primary

Intended audience is basic R users (or those interested in seeing what R can do), who wish integrate spatial data into their “regular” (exploratory) data-analysis workflow, or who need a quick map. More advanced GIS-topics such as projection fall outside of the scope.

The material and examples are structured along the basic steps you generally take when making thematic maps:

  1. Motivating examples of static and interactive thematic maps.
  2. Get an appropriate blank map to visualise your data on, e.g. from Belgium, Europe or the world.
  3. Load and add the data-of-interest you wish to visualise.
  4. Jointly manipulate your spatial and “regular” data.
  5. Finally, plot and tweak your map. E.g. choosing color palettes, multiple maps, styling, etc.

I like hearing from you if this walkthrough has been useful somehow, if something is not working or can be improved, or if you are interested in a workshop.

Download the material

You can copy-past the code snippets from the online pages, download (25MB) the entire set of material, or clone from Github.

Opening the file thematic_maps_with_r.Rproj in the downloaded folder launches an Rstudio-project, after which you should be able to open, adapt, and run the Rmarkdown notebooks containing the examples (files ending in .Rmd).

Setup

  1. Download and install R.
  2. Download and install Rstudio.
  3. Run commands below to install required R-packages.
install.packages('rmarkdown')
install.packages('sf')
install.packages('tmap')
install.packages('dplyr')
install.packages('readxl')
install.packages('eurostat')
install.packages('leaflet')
install.packages('haven')
install.packages('mapview')
install.packages('rgdal')
install.packages('tmaptools')
install.packages('countrycode')
install.packages('stringr')
install.packages('readr')
install.packages('ggplot2')
install.packages('htmlwidgets')
install.packages('rworldmap')
install.packages('lubridate')

install.packages("BelgiumMaps.StatBel", repos = "http://www.datatailor.be/rcube", type = "source")