Authors

Andree Valle Campos

Laure Vancauwenberghe

Kene David Nwosu

Published

December 2, 2024


1 Introduction

• Spatial data may require geographic context

• Aids to locate events with environmental features like streets.

Figure 1. (A) John Snow’s Dot map. (B) John Snow’s Dot map complemented with the city street roads.

• Today, we are going to learn:• How to add Physical features to our maps, and

• How to plot them in multiple layers to complement Thematic maps!


2 Learning objectives

  1. Create Physical feature maps to visualize roads or rivers.

  2. Complement Thematic maps with Physical features as background.

  3. Relate Physical features with a Geometry type.


3 Prerequisites

This lesson requires the following packages:

Code
if(!require('pacman')) install.packages('pacman')
pacman::p_load_gh("afrimapr/afrilearndata")
pacman::p_load(ggspatial,
               ggplot2,
               tibble,
               mdsr,
               terra,
               spData,
               sf, 
               readr)

This lesson requires familiarity with {ggplot2}: if you need to brush up, have a look at our introductory course on data visualization.


4 Physical features

What are they?

Physical features include roads, buildings and rivers.

How to plot them?

• Using {ggplot2}, geom_sf(), and the color argument.

With Categorical data

• Let’s map the Road network in South America and color them according to their type:

Code
south_am_roads <- 
  read_rds(here("data/south_am_roads.rds"))

ggplot(south_am_roads) +
  geom_sf(mapping = aes(color = type))

Let’s create a map of the Sacramento basin in California US (sacramento_rivers), colored by their feature type (FTYPE).

Code
sacramento_rivers <- 
  read_rds(here("data/sacramento_rivers.rds"))

# CONTINUE YOUR CODE HERE
ggplot(sacramento_rivers) +
  geom_sf(mapping = aes(color = FTYPE), size = 1)

Data from here: https://zenodo.org/record/4985219

With Quantitative data

• We can use it in Environmental Epidemiology,

• The concentration of chemicals or pollutants in wastewater surveillance.

• In Ecology, richness estimations from rivers.

• Let’s map a classification of rivers in the Sacramento basin in California US.

Code
sacramento_rivers <- 
  read_rds(here("data/sacramento_rivers.rds"))

ggplot(data = sacramento_rivers) +
  geom_sf(mapping = aes(color = richness))

• “Richness” is the estimated number of fish species in each segment of the river.

Create a Thematic map of the road network in South America, using the south_am_roads dataset, colored by the length in Km (length_km) of each road.

Code
ggplot(data = south_am_roads) +
  geom_sf(mapping = aes(color = length_km), size = 1)

How to use it?

Trajectory data and Road network data

• Evaluate the effects of human movement patterns in infectious disease transmission like Dengue or Malaria.

Figure 2. (A) Human mobility by follow-up GPS tracks (Falcón-Lezama et al. 2017). (B) Road network map of Kenia with traffic data (Pindolia et al. 2012).

• Both of them are depicted in a map using Lines.

• Each Thematic map has its respective type of Geometry.

• There are three main geometry types: points, lines and polygons.

Figure 2. Geometry types and example maps for each. Points, lines (or linestrings) and polygons are the most common geometries you will encounter.

5 Multiple layer maps

• Most maps need additional geographic context.

• Plotting multiple geometries in overlapped layers.

• Complement Thematic maps with Physical features.

How to plot them?

• Let’s complement a Choropleth map with the population (pop_est) of African countries, from the africountries dataset with: the African trans-continental highway network lines, available in the afrihighway dataset from the same package.

Code
ggplot() +
  geom_sf(data = africountries , mapping = aes(fill = pop_est)) +
  geom_sf(data = afrihighway)

• Here, the physical feature afrihighway is above all the other layers.

• But it can also be below.

• We can complement a Dot map from africapitals, with the same afrihighway layer:

Code
ggplot() +
  geom_sf(data =  afrihighway) +
  geom_sf(data = africapitals, mapping = aes(size = pop, color = pop))

• This is how you plot another map layer on top of another map.

{ggplot2} allows to overlap multiple layers (of maps) to complement Thematic maps.

• For this, You need a local specification of data:

# instead of:
ggplot(data = data_global) +
  geom_sf()

# we use:
ggplot() +
  geom_sf(data = data_local_layer_1) +
  geom_sf(data = data_local_layer_2)

Order of layers (below or above) depend on the aim.

Create a multiple layer Thematic map with:

  • the world dataset (from the {spData} package).

  • Then, overlap it with the African trans-continental highway network lines from the afrihighway dataset.

Use the geom_sf() function for each layer:

Code
  ggplot() + 
    geom_sf(data = world) + 
    geom_sf(data = afrihighway)

How to use it?

• In scenarios similar to John Snow’s Dot map

• Locations of deaths of the 1854 London cholera outbreak.

• Complemented with a physical feature like the street roads of the city:

Figure 3. (A) John Snow’s Dot map. (B) John Snow’s Dot map complemented with the city street roads.

• In Figure 3B, the physical feature is below the Dot map.

• This is why it looks much more readable.


6 Wrap up

• How to represent Physical features and

• How to use them to complement Thematic maps in multiple layers.

Figure 4. Concept map #2.

• However, you may require a more explicit background!

• For example, Basemaps for Google Maps-like backgrounds.

• See you in the next lesson!


Contributors

The following team members contributed to this lesson:


References

Some material in this lesson was adapted from the following sources:

This work is licensed under the Creative Commons Attribution Share Alike license. Creative Commons License


Answer Key

Q1

Code
sacramento_rivers <- 
  read_rds(here("data/sacramento_rivers.rds"))

ggplot(data = sacramento_rivers) + 
    geom_sf(aes(color = FTYPE), size = 1)

Q2

Code
south_am_roads <- 
  read_rds(here("data/south_am_roads.rds"))

ggplot(data = south_am_roads) + 
    geom_sf(aes(color = length_km), size = 1)

Q3

Code
ggplot() + 
    geom_sf(data = world) + 
    geom_sf(data = afrihighway)