Skip to content

Instantly share code, notes, and snippets.

librarian::shelf(tidyverse, pdftools, msthemes, ggtext, showtext)
# Add Google fonts
font_add_google("Alfa Slab One", "alfa")
font_add_google("Roboto Mono", "space", regular.wt = 200)
showtext_opts(dpi = 320)
showtext_auto(enable = TRUE)
# Download PDF:
# https://www.oegb.at/content/dam/oegb/downloads/der-ögb/Streikstatistik_2021.pdf
@mschnetzer
mschnetzer / inflation_history.R
Last active October 21, 2022 16:00
Monatliche Inflationsraten in Österreich seit 1960 (https://twitter.com/matschnetzer/status/1583451964352102405)
librarian::shelf(tidyverse, janitor, ggridges, ggtext, glue, colorspace, MetBrewer, msthemes, ggforce)
rawdata <- read.csv2("https://data.statistik.gv.at/data/OGD_vpi58ii_VPI_1958_ii_1.csv")
inflation <- rawdata |>
mutate(datum = ym(str_extract(C.VPIZR.0, "(\\d)+"))) |>
select(datum, Index = F.VPIMZBM) |>
drop_na() |>
mutate(Inflation = (Index - lag(Index,12))/lag(Index,12)*100,
decade = factor(floor(year(datum)/10)*10))
@mschnetzer
mschnetzer / inflation_auto.R
Created August 18, 2022 09:28
Inflation-Stream mit Open Data von Statistik Austria
librarian::shelf(tidyverse, janitor, ggstream, ggtext, colorspace, MetBrewer, msthemes)
rawdata <- read.csv2("https://data.statistik.gv.at/data/OGD_vpi15_VPI_2015_1.csv")
coicop <- read.csv2("https://data.statistik.gv.at/data/OGD_vpi15_VPI_2015_1_C-VPI5-0.csv")
inflation <- rawdata %>%
mutate(datum = ym(str_extract(C.VPIZR.0, "(\\d)+"))) %>%
left_join(coicop %>% select(code, name), by = c("C.VPI5.0"="code")) %>%
select(datum, Coicop = name, Beitrag = F.VPIEFVJM) %>%
drop_na() %>%
@mschnetzer
mschnetzer / inflation.R
Last active July 28, 2022 18:10
Inflationsentwicklung nach ausgewählten COICOP-Kategorien (https://twitter.com/matschnetzer/status/1552716619482374151)
librarian::shelf(tidyverse, msthemes, janitor, lubridate, ggstream, MetBrewer, ggtext)
# Data from statcube.at
raw <- readxl::read_xlsx("table_2022-07-27_23-59-52.xlsx", na = "-", sheet = "Data Sheet 0", range = "B11:AU57")
inflation <- raw %>%
clean_names() %>%
mutate(Wohnen = x04_wohnung_wasser_energie - x04_5_aufwand_fur_energie) %>%
select("Datum" = "x1",
"Inflation" = "gesamtindex_nach_coicop",
@mschnetzer
mschnetzer / hitzetage.R
Last active July 18, 2022 09:40
Anzahl der Hitzetage in Wien und Österreich (https://twitter.com/matschnetzer/status/1548947293889511424)
library(tidyverse)
library(lubridate)
library(msthemes)
library(geojsonsf)
library(sf)
# Get data: https://dataset.api.hub.zamg.ac.at/app/station-new/historical/klima-v1-1d?anonymous=true
tempdat <- read.csv("TAG Datensatz_19500101_20211231.csv") %>%
mutate(name = case_when(
library(tidyverse)
library(lubridate)
library(msthemes)
library(gganimate)
# Get data from https://zamg.ac.at/histalp/dataset/station/csv.php
raw <- read_csv2("HISTALP_AT_WIE_T01_1760_2025.csv", skip = 13)
temp <- raw %>% select(year:dec) %>%
pivot_longer(names_to = "month", values_to = "value", cols = jan:dec) %>%
@mschnetzer
mschnetzer / heat_record.R
Last active December 12, 2022 19:25
Year of highest temperatures ever recorded by a country (https://twitter.com/matschnetzer/status/1602260127536799745)
library(tidyverse)
library(rvest)
library(stringi)
library(janitor)
library(countrycode)
library(MetBrewer)
library(msthemes)
library(patchwork)
url <- "https://en.wikipedia.org/wiki/List_of_weather_records#Highest_temperatures_ever_recorded"
@mschnetzer
mschnetzer / covidmap_bivariate.R
Created January 5, 2022 16:56
Bivariate map for vaccinations and covid cases in Austria (https://twitter.com/matschnetzer/status/1478750626339303424)
#############
#### ACKNOWLEDGMENTS
#############
# Thanks for the original idea and the helpful code to @grssnbchr and @benjazehr: https://timogrossenbacher.ch/2019/04/bivariate-maps-with-ggplot2-and-sf/
#############
#### LOAD PACKAGES
#############
@mschnetzer
mschnetzer / hexagon.R
Created November 12, 2021 10:13
3d Hexagon Map for Covid in Austria [experimental] (https://twitter.com/matschnetzer/status/1459092614318333957?s=20)
library(tidyverse)
library(sf)
library(msthemes)
library(rayshader)
library(wesanderson)
# Download the map here: https://github.com/ginseng666/GeoJSON-TopoJSON-Austria/tree/master/2021
map <- st_read("bezirke_999_geo.json") %>%
mutate(iso = as.numeric(iso),
iso = ifelse(iso %in% 901:923, 900, iso)) %>%
library(tidyverse)
library(ggbump)
library(msthemes)
library(rnaturalearth)
library(rnaturalearthdata)
library(lubridate)
library(sf)
covid <- read_csv("owid-covid-data.csv") %>% filter(continent == "Europe") %>%
group_by(iso_code) %>% drop_na(people_vaccinated_per_hundred) %>%