library(tidyverse)
library(readxl)
library(geofacet)
url <- "http://www.data.efv.admin.ch/Finanzstatistik/d/fs_ktn/ktn_schuld.xlsx"
tf <- tempfile(fileext = ".xlsx")
download.file(url, tf)
dta <- read_excel(tf, sheet = "schuld_per_capita", skip = 6) %>%
select(-X__1) %>%
rename(geo = CHF) %>%
gather(-geo, key = "year", value = "value") %>%
filter(geo != "Kantone") %>%
mutate(year = as.integer(year)) %>%
mutate(geo = gsub("Kanton ", "", geo)) %>%
mutate(geo = gsub("Sankt Gallen", "St.Gallen", geo)) %>%
mutate(geo = gsub(" ", "-", geo))
ggplot(dta, aes(x = year, y = value)) +
geom_line() +
theme_bw() +
facet_geo(~ geo, grid = ch_cantons_grid2) +
ggtitle("gross debt of swiss cantons", subtitle = "per capita")
#> Note: You provided a user-specified grid. If this is a
#> generally-useful grid, please consider submitting it to become a
#> part of the geofacet package. You can do this easily by calling:
#> grid_submit(__grid_df_name__)
Created on 2018-05-31 by the reprex package (v0.2.0).