Skip to content

Instantly share code, notes, and snippets.

@jmcastagnetto
Last active January 13, 2022 13:33
Show Gist options
  • Save jmcastagnetto/6b1d0983cd5ffefa8bcf07caa003b983 to your computer and use it in GitHub Desktop.
Save jmcastagnetto/6b1d0983cd5ffefa8bcf07caa003b983 to your computer and use it in GitHub Desktop.
Plot map of Peru's Commuting Zones and of its provinces as comparison
# Using data from https://data.humdata.org/dataset/commuting-zones
library(tidyverse)
library(sf)
library(geodata)
library(patchwork)
peru_map <- gadm("Peru", level = 2, path = ".") %>%
st_as_sf()
csv <- "~/Downloads/data-for-good-at-meta-commuting-zones-july-2021.csv"
df <- read_csv(csv)
sf_df <- st_as_sf(df, wkt = "geometry")
peru <- sf_df %>% filter(country == "Peru")
peru_provs <- ggplot() +
geom_sf(data = peru_map, size = .2, color = "black", fill = NA) +
scale_x_continuous(limits = c(-82, -64)) +
scale_y_continuous(limits = c(-20, 0)) +
labs(
title = "Peru: Provinces"
) +
theme_void(20)
peru_commute <- ggplot() +
geom_sf(data = peru, size = .2, color = "blue", fill = NA) +
scale_x_continuous(limits = c(-82, -64)) +
scale_y_continuous(limits = c(-20, 0)) +
labs(
title = "Peru: Commuting Zones",
subtitle = "Source: Facebook Commuting Zones (HUMDATA)"
) +
theme_void(20)
peru_provs + peru_commute
@jmcastagnetto
Copy link
Author

Peru: commuting zones and provinces

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment