Chapter 6 Custom and Animated Maps

6.1 Learning Objectives

  • Use urban_agglomerations and world data from the spData package
  • Make the same map in ggplot2 and tmap
  • Make an animated map and save it

6.2 Functions Learned

  • tm_shape
  • tm_polygons
  • tm_dots
  • tm_facets
  • tmap_animation

6.3 Interactive Tutorial

This workshop’s R Markdown can be found here.

6.4 Challenges

This workshop uses an example from Geocomputation with R, developed by Robin Lovelace. The original script can be found online.

If you get the following error, make sure the magick package is installed with install.packages(“magick”), and that ImageMagick itself is installed:

Error in tmap::tmap_animation(tm, filename = “doc/city-pop.gif”) : Could not find ImageMagick. Make sure it is installed and included in the systems PATH

Challenge

  1. Look at the urban_agglomerations and the world data. What type of spatial data is each (point, line, polygon)? How many observations are in each dataset?

  2. What projection is each in?

  3. Make a ggplot2 map of both datasets

Challenge

  1. Make a tmap map of urban_agglomerations.

Challenge

  1. Change the color of the points to one of your choosing.

Luc Anselin has written a more in-depth tutorial for tmap, which you can find and go through here, under Introduction to Spatial Data Science > Basic Mapping.