8.7 Exercises

These exercises rely on a new object, africa.Create it using the world and worldbank_df datasets from the spData package as follows (see Chapter 3):

  1. africa = world %>%
  2. filter(continent == "Africa", !is.na(iso_a2)) %>%
  3. left_join(worldbank_df, by = "iso_a2") %>%
  4. dplyr::select(name, subregion, gdpPercap, HDI, pop_growth) %>%
  5. st_transform("+proj=aea +lat_1=20 +lat_2=-23 +lat_0=0 +lon_0=25")

We will also use zion and nlcd datasets from spDataLarge:

  1. zion = st_read((system.file("vector/zion.gpkg", package = "spDataLarge")))
  2. data(nlcd, package = "spDataLarge")
  • Create a map showing the geographic distribution of the Human Development Index (HDI) across Africa with base graphics (hint: use plot()) and tmap packages (hint: use tm_shape(africa) + …).
    • Name two advantages of each based on the experience.
    • Name three other mapping packages and an advantage of each.
    • Bonus: create three more maps of Africa using these three packages.
  • Extend the tmap created for the previous exercise so the legend has three bins: “High” (HDI above 0.7), “Medium” (HDI between 0.55 and 0.7) and “Low” (HDI below 0.55).
    • Bonus: improve the map aesthetics, for example by changing the legend title, class labels and color palette.
  • Represent africa’s subregions on the map.Change the default color palette and legend title.Next, combine this map and the map created in the previous exercise into a single plot.
  • Create a land cover map of the Zion National Park.
    • Change the default colors to match your perception of the land cover categories
    • Add a scale bar and north arrow and change the position of both to improve the map’s aesthetic appeal
    • Bonus: Add an inset map of Zion National Park’s location in the context of the Utah state. (Hint: an object representing Utah can be subset from the us_states dataset.)
  • Create facet maps of countries in Eastern Africa:
    • With one facet showing HDI and the other representing population growth (hint: using variables HDI and pop_growth, respectively)
    • With a ‘small multiple’ per country
  • Building on the previous facet map examples, create animated maps of East Africa:
    • Showing first the spatial distribution of HDI scores then population growth
    • Showing each country in order
  • Create an interactive map of Africa:
    • With tmap
    • With mapview
    • With leaflet
    • Bonus: For each approach, add a legend (if not automatically provided) and a scale bar
  • Sketch on paper ideas for a web mapping app that could be used to make transport or land-use policies more evidence based:
    • In the city you live, for a couple of users per day
    • In the country you live, for dozens of users per day
    • Worldwide for hundreds of users per day and large data serving requirements
  • Update the code in coffeeApp/app.R so that instead of centering on Brazil the user can select which country to focus on:
    • Using textInput()
    • Using selectInput()
  • Reproduce Figure 8.1 and the 1st and 6th panel of Figure 8.6 as closely as possible using the ggplot2 package.
  • Join us_states and us_states_df together and calculate a poverty rate for each state using the new dataset.Next, construct a continuous area cartogram based on total population.Finally, create and compare two maps of the poverty rate: (1) a standard choropleth map and (2) a map using the created cartogram boundaries.What is the information provided by the first and the second map?How do they differ from each other?
  • Visualize population growth in Africa.Next, compare it with the maps of a hexagonal and regular grid created using the geogrid package.

References

Murrell, Paul. 2016. R Graphics. Second. CRC Press.

Brewer, Cynthia A. 2015. Designing Better Maps: A Guide for GIS Users. Second. Redlands, California: Esri Press.

Talbert, Richard J. A. 2014. Ancient Perspectives: Maps and Their Place in Mesopotamia, Egypt, Greece, and Rome. University of Chicago Press.

Pebesma, Edzer J, and Roger S Bivand. 2005. “Classes and Methods for Spatial Data in R.” R News 5 (2): 9–13.

Cheshire, James, and Robin Lovelace. 2015. “Spatial Data Visualisation with R.” In Geocomputation, edited by Chris Brunsdon and Alex Singleton, 1–14. SAGE Publications.

Tennekes, Martijn. 2018. “Tmap: Thematic Maps in R.” Journal of Statistical Software, Articles 84 (6): 1–39. https://doi.org/10.18637/jss.v084.i06.

Wilkinson, Leland, and Graham Wills. 2005. The Grammar of Graphics. Springer Science+ Business Media.

Borland, David, and Russell M Taylor II. 2007. “Rainbow Color Map (Still) Considered Harmful.” IEEE Computer Graphics and Applications 27 (2). IEEE.

Meulemans, Wouter, Jason Dykes, Aidan Slingsby, Cagatay Turkay, and Jo Wood. 2017. “Small Multiples with Gaps.” IEEE Transactions on Visualization and Computer Graphics 23 (1): 381–90. https://doi.org/10.1109/TVCG.2016.2598542.

Pezanowski, Scott, Alan M MacEachren, Alexander Savelyev, and Anthony C Robinson. 2018. “SensePlace3: A Geovisual Framework to Analyze PlaceTimeAttribute Information in Social Media.” Cartography and Geographic Information Science 45 (5): 420–37. https://doi.org/10.1080/15230406.2017.1370391.

Lovelace, Robin, Anna Goodman, Rachel Aldred, Nikolai Berkoff, Ali Abbas, and James Woodcock. 2017. “The Propensity to Cycle Tool: An Open Source Online System for Sustainable Transport Planning.” Journal of Transport and Land Use 10 (1). https://doi.org/10.5198/jtlu.2016.862.

Wickham, Hadley. 2016. Ggplot2: Elegant Graphics for Data Analysis. Second. New York, NY: Springer.


  • If there is a clash between a fixed value and a column name, the column name takes precedence. This can be verified by running the next code chunk after running nz$red = 1:nrow(nz).

  • col = "MAP_COLORS" can be used in maps with a large number of individual polygons (for example, a map of individual countries) to create unique colors for adjacent polygons.

  • See the “Color blindness simulator” options in tmaptools::palette_explorer().

  • The word ‘app’ in this context refers to ‘web application’ and should not be confused with smartphone apps, the more common meaning of the word.