1 Introduction

Most times spatial data requires geographic context to locate events with environmental features like rivers or streets.

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

In this lesson, we are going to learn about how to add Physical features to our maps and 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:

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

4.1 What are they?

Physical features include roads, buildings and rivers.

4.2 How to plot them?

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

4.2.1 With Categorical data

We can create a Physical feature map of the Road network in South America and color them according to their type:

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

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

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

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

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

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

4.2.2 With Quantitative data

In Environmental Epidemiology, we can map numeric variables like the concentration of chemicals or pollutants in wastewater surveillance, or in Ecology, richness estimations from rivers.

Below is an example mapping a classification of rivers in the Sacramento basin in California US.

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.

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

4.3 How to use it?

We can use Trajectory data and Road network data to 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).
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.

  • “Geometry” is essentially a synonym for “Shape”.
  • There are three main geometry types: points, lines and polygons.
Figure 3. Geometry types and example maps for each. Points, lines (or linestrings) and polygons are the most common geometries you will encounter.
Figure 3. 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

So far we have been plotting single geometries. But for most maps, you will need to provide additional context. This can be done by plotting multiple geometries.

We can complement Thematic maps with spatial Physical features like roads, buildings and rivers.

5.1 How to plot them?

As an example, we will complement a Choropleth map with the population (pop_est) of African countries, from the africountries, with:

  • the African trans-continental highway network lines, available in the afrihighway dataset from the same package.
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. For example, we can complement a Dot map with the population in the capital cities of Africa, from the africapitals dataset, with the same layer:

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) from different data sources to complement Thematic maps.

For this, instead of a global specification of data, you need a local specification of data:

# instead of:
ggplot(data = data_global) +
  geom_sf()
## Error in ggplot(data = data_global): object 'data_global' not found
# we use:
ggplot() +
  geom_sf(data = data_local_layer_1) +
  geom_sf(data = data_local_layer_2)
## Error in fortify(data): object 'data_local_layer_1' not found

The order of the layers (below or above) will depend on the aim of the plot.

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:

q1 <- 
  ggplot() + 
    ________(data = ________) + 
    ________(data = ________)
q1

5.2 How to use it?

In this example, we replicate John Snow’s Dot map with the locations of deaths of the 1854 London cholera outbreak. We complemented this map with a physical feature like the street roads of the city: subfigure B is much more readable than subfigure A right?!

Figure 4. (A) John Snow’s Dot map. (B) John Snow’s Dot map complemented with the city street roads.
Figure 4. (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 used as background, below the Dot map. This is why it looks much more readable.

6 Wrap up

In this lesson, we have learned about how to represent Physical features and how to use them to complement Thematic maps in multiple layers.

Figure 5. Concept map #2.
Figure 5. Concept map #2.

However, most times spatial data requires more explicit Google Maps-like geographic context! For this you will need to learn how to add Basemaps for Google Maps-like backgrounds. Follow along with the lessons to find how to do this!

Answer Key

Q1

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

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

Q2

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

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

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