Skip to content

Instantly share code, notes, and snippets.

@charliejhadley
Last active September 7, 2021 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charliejhadley/9d13ac12a887603b26a1b57342c3d474 to your computer and use it in GitHub Desktop.
Save charliejhadley/9d13ac12a887603b26a1b57342c3d474 to your computer and use it in GitHub Desktop.
R for the Rest of Us - Mapping with R - Disambiguating country names with {countrycode}
library(tidyverse)
library(sf)
library(rnaturalearthdata)
library(countrycode)
library(gapminder)
library(mapview)
gapminder_2007 <- gapminder %>%
filter(year == 2007)
gapminder_2007 <- gapminder_2007 %>%
mutate(iso_3c = countryname(country, "iso3c"))
countries_sf <- countries110 %>%
st_as_sf()
countries_sf %>%
left_join(gapminder_2007,
by = c("iso_a3" = "iso_3c")) %>%
mapview(zcol = "lifeExp")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment