Making outline maps

Andrew Irwin, a.irwin@dal.ca

2024-03-19

Plan

  • Kinds of maps

  • Basic maps

  • Adding points

  • Shading areas

  • Projections

Map libraries

  • ggmap (part of tidyverse)

  • Many other libraries

    • maps
    • mapproj for making projections of the Earth’s surface
    • mapdata with maps of China and Japan
    • leaflet for drawing raster or tiled maps (next lesson)

Kinds of maps

  • Coastlines and political boundaries

  • Natural features (rivers, water bodies)

  • Points and filled regions on maps

  • How to represent latitude and longitude from a sphere on a screen?

  • Tiled maps

A basic map

library(tidyverse)
WorldData <- map_data('world')  
m1 <- ggplot(WorldData) + 
        geom_map(map = WorldData,
                 aes(map_id = region),
                 fill = "lightgray", colour = "#7f7f7f", 
                 alpha = 0.5, linewidth=0.5) +
  expand_limits(x = c(-180, 180), y = c(-85, 85)) + 
  theme_bw()

A basic map

Colour countries

values <- tibble( region = WorldData |> pull(region) |> unique())
values <- values |> mutate(value = runif(nrow(values)))
m2 <- values |> ggplot() + 
        geom_map(aes(fill = value, map_id = region),
                 map = WorldData,
                 colour = "lightgray", 
                 alpha = 1, linewidth=0.5) +
   expand_limits(x = c(-180,180), y = c(-80,80)) +
   theme_bw()

Colour countries

Show only some countries

values <- tibble( region = c("Canada", "China", "Chile"),
                  value  = c(1, 2, 3))
m3 <- values |> ggplot() + 
        geom_map(aes(fill = value, map_id = region),
                 map = WorldData,
                 colour = "lightgray", 
                 alpha = 1, linewidth=0.5) +
   expand_limits(x = c(-180,180), y = c(-80,80))+
  theme_bw()

Show some countries

Colour some countries

values <- tibble( region = c("Canada", "China", "Chile"),
                  value  = c(1, 2, 3))
m4 <- ggplot(data = WorldData, aes(map_id = region)) + 
        geom_map(map = WorldData,
                 colour = "lightgray", fill = "darkgray",
                 alpha = 1, linewidth=0.5) +
        geom_map(aes(fill = value), 
                 data = values, map = WorldData) + 
   expand_limits(x = c(-180,180), y = c(-80,80))+
  theme_bw()

Colour some countries

Add points

library(rnaturalearth)
library(rnaturalearthdata)
library(ggrepel)
canada <- ne_countries(country = "canada", scale = "large", 
                       returnclass = "sf")
sites <- tibble(longitude = c(-81, -80), latitude = c(44, 45), 
                label = c("A", "B"))
m5 <- ggplot(data = canada) +
      geom_sf() +
      geom_point(data = sites, 
                 aes(x = longitude, y = latitude), 
                 size = 4, shape = 21, fill = "darkred") +
  geom_label_repel(data = sites, 
                   aes(x = longitude, y = latitude, 
                       label = label)) + 
  coord_sf(xlim = c(-140,-50), ylim = c(42,65))

Add points

Projections

library(mapproj)
CanadaData <- map_data('world', 'Canada')  
m6 <- ggplot(CanadaData, aes(map_id=region)) + 
        geom_map(map = CanadaData,
                 aes(x = long, y = lat),
                 fill = "lightgray", colour = "#7f7f7f", 
                 alpha = 0.5, linewidth=0.5) +
  theme_bw() +
  coord_map("lambert", lat0 = 42, lat1 = 50)

Projections

Polar regions

library(mapproj)
m7 <- ggplot(WorldData, aes(map_id=region)) + 
        geom_map(map = WorldData,
                 aes(x = long, y = lat),
                 fill = "lightgray", colour = "#7f7f7f", 
                 alpha = 0.5, linewidth=0.5) +
  theme_bw() +
  coord_map("perspective", 2, orientation=c(-90, -90, 90))

Polar regions

Summary

  • Make a basic map

  • Select all or some countries

  • Fill regions with colour

  • Add points and labels

  • Use a different projection

Task

  • Bonus task - make some simple maps based on course notes