Skip to content

Instantly share code, notes, and snippets.

@christophsax
Created May 31, 2018 20:15
Show Gist options
  • Save christophsax/3532a29418cf1caaffc27d9e3ad30f2d to your computer and use it in GitHub Desktop.
Save christophsax/3532a29418cf1caaffc27d9e3ad30f2d to your computer and use it in GitHub Desktop.
gross debt of swiss cantons
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).

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