Skip to content

Instantly share code, notes, and snippets.

@sschmutz
Last active January 25, 2019 21:56
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 sschmutz/bf0ad51ce2c810e323cbed4348fe8c84 to your computer and use it in GitHub Desktop.
Save sschmutz/bf0ad51ce2c810e323cbed4348fe8c84 to your computer and use it in GitHub Desktop.
get data and plot map of Switzerland on a canton level
# load packages -----------------------------------------------------------
library(here)
library(sf)
library(ggplot2)
# download and read map data ----------------------------------------------
url_gadm <- "https://biogeo.ucdavis.edu/data/gadm3.6/shp/gadm36_CHE_shp.zip"
download.file(url = url_gadm,
destfile = here("gadm36_CHE_shp.zip"))
unzip(zipfile = here("gadm36_CHE_shp.zip"),
exdir = here("gadm36_CHE_shp"))
gadm36_CHE_1 <- read_sf(dsn = here("gadm36_CHE_shp", "gadm36_CHE_1.shp"))
# explore the dataset -----------------------------------------------------
head(gadm36_CHE_1)
# plot the map ------------------------------------------------------------
map_switzerland <-
gadm36_CHE_1 %>%
ggplot() +
geom_sf() +
coord_sf(datum = NA) +
theme_void()
ggsave(filename = here("map_switzerland.png"), plot = map_switzerland)
@sschmutz
Copy link
Author

map_switzerland

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