Skip to content

Instantly share code, notes, and snippets.

View mschnetzer's full-sized avatar

Matthias Schnetzer mschnetzer

View GitHub Profile
@mschnetzer
mschnetzer / jobfamily.R
Created December 7, 2022 18:11
Erwerbsverläufe von Männern und Frauen mit Kindern (https://twitter.com/matschnetzer/status/1600058999306690560)
library(tidyverse)
library(waffle)
library(msthemes)
library(MetBrewer)
library(showtext)
df <- tribble(
~Geschlecht, ~Status, ~"<1", ~"1", ~"2", ~"3-5", ~"6-9", ~"10-14",
"Männer", "Vollzeit", 84.4, 83.2, 82.5, 83.7, 85.2, 83.5,
"Frauen", "Vollzeit", 8.6, 6, 11.9, 16.4, 20.1, 30.7,
@mschnetzer
mschnetzer / hitzetage.R
Created December 5, 2022 17:30
Hitzetage in Wien und den Bundesländern mit ZAMG API (https://twitter.com/matschnetzer/status/1599781018575044608)
library(tidyverse)
library(lubridate)
library(httr)
library(jsonlite)
library(msthemes)
library(geojsonsf)
library(sf)
# Get data: https://dataset.api.hub.zamg.ac.at/app/station-new/historical/klima-v1-1d?anonymous=true or use API like here
librarian::shelf(tidyverse, sf, ows4R, httr, msthemes, osmdata, RColorBrewer, ggtext, showtext)
# Add Google fonts
font_add_google(name = "Bodoni Moda", family = "bodoni")
font_add_google(name = "Roboto Slab", family = "roboto-slab")
font_add_google(name = "Roboto Slab", family = "roboto-slab-thin", regular.wt = 300, bold.wt = 500)
showtext_auto()
# Define map boundaries
bb <- c(16.3151, 48.1856, 16.4087, 48.2279)
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"