Skip to content
R for the Rest of Us Logo

Mapping with R

Choosing a Projection

Transcript

Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.

View code shown in video
library(tidyverse)
library(rnaturalearth)
library(sf)
library(tigris)
library(crsuggest)

all_countries <-
  ne_countries() |>
  select(sovereignt)

all_countries

all_countries |>
  ggplot() +
  geom_sf()

# Robinson

all_countries |>
  st_transform(
    "+proj=robin +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs"
  ) |>
  ggplot() +
  geom_sf()

# Gall-Peters

all_countries |>
  st_transform(
    "+proj=cea +lon_0=0 +lat_ts=45 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs"
  ) |>
  ggplot() +
  geom_sf()

# Mollweide

all_countries |>
  st_transform("+proj=moll +datum=WGS84 +units=m") |>
  ggplot() +
  geom_sf()

# Lambert Azimuthal Equal-Area Projection

all_countries |>
  st_transform("+proj=laea +x_0=0 +y_0=0 +lon_0=0 +lat_0=0") |>
  ggplot() +
  geom_sf()

africa <-
  ne_countries(continent = "Africa") |>
  select(sovereignt)

africa |> 
  ggplot() +
  geom_sf()

africa_crs <- 
africa |> 
  suggest_top_crs()

africa |> 
  st_transform(africa_crs) |> 
  ggplot() +
  geom_sf()


continental_us_states <-
  states() |>
  select(NAME) |>
  filter(NAME %in% state.name) |>
  filter(NAME != "Alaska") |>
  filter(NAME != "Hawaii")

us_crs <- 
continental_us_states |> 
  suggest_top_crs()

continental_us_states |>
  st_transform(us_crs) |> 
  ggplot() +
  geom_sf()

Your Turn

  1. Improve the map you made in the last lesson on the number of refugees from each country in the world by using the crsuggest package to find the best projection for the data.

  2. Once you’ve done this, redo your map with this projection.

Learn More

The projections I showed were inspired by this Bluesky post by the user Pokateo Maps.

The Axios video on projections is great. You should watch the whole thing!

To learn more about the {crsuggest} package, check it out on GitHub. To learn about projections generally, check out Chapter 7 of Geocomputation with R.

Have any questions? Put them below and we will help you out!

You need to be signed-in to comment on this post. Login.