Skip to content

Instantly share code, notes, and snippets.

@mschnetzer
mschnetzer / bubbleptft.r
Last active August 14, 2018 16:36
Change in ratio part/full time employees 2007-2017 (https://twitter.com/matschnetzer/status/1024882484255903744)
# Adapted from https://jschoeley.github.io/2018/06/30/bubble-grid-map.html
library(eurostat)
library(tidyverse)
library(lubridate)
library(sf)
library(lwgeom)
library(msthemes)
# download eurostat data for nuts 2 regions
@mschnetzer
mschnetzer / warmingstripes.r
Last active April 29, 2020 10:24
Durchschnittliche Lufttemperatur in Wien 1775-2017 (https://twitter.com/matschnetzer/status/1029246243741032448)
library(tidyverse)
library(msthemes) # https://github.com/mschnetzer/msthemes
# Get data from http://www.zamg.ac.at/histalp/dataset/station/csv.php
data <- read_csv2("HISTALP_AT_WIE_T01_1760_2025.csv", skip = 13)
data <- data %>% mutate_at(vars("jan-dec"), list(temp = ~ .*0.1)) %>%
select(year, temp) %>% filter(year %in% c(1775:2019)) %>%
mutate(abw = log(temp/mean(temp)))
data$draw <- 1
@mschnetzer
mschnetzer / marriage.r
Created August 30, 2018 17:49
Mean age at first marriage, 1990-2014
library(tidyverse)
library(msthemes)
library(eurostat)
# Download data from UNECE: http://bit.ly/2wtn9Sp
data <- read.csv("marriage.csv",skip=1,na.strings=c("","..","NA"),dec=".")
data <- data %>% gather(year,value, -Sex, -Country)
data$year <- as.numeric(substring(data$year, 2))
# Change in EU countries where data is available
@mschnetzer
mschnetzer / wtg_gdppc.r
Last active September 4, 2018 13:05
World Tile Grid of Quintiles of GDP per capita, 1995-2015 (https://twitter.com/matschnetzer/status/1036879668606107648)
library(worldtilegrid)
library(plyr)
library(tidyverse)
library(countrycode)
library(viridis)
library(msthemes)
# Get GDP per capita data from UNdata http://bit.ly/2N4hUlV
data <- read.csv("undata.csv",dec=".") %>% rename(Country=Country.or.Area) %>% select(-Value.Footnotes)
@mschnetzer
mschnetzer / sciencepop.R
Created September 20, 2018 10:37
Scientists and engineers per 1,000 pop
library(tidyverse)
library(eurostat)
sci <- get_eurostat("hrst_st_nocc",filters=list(geo=eu_countries$code,unit="THS",isco08="TOTAL",category="SE",age="Y25-64",lastTimePeriod=1),type="code",time_format = "num") %>%
select(geo,values) %>% rename(sci=values)
pop <- get_eurostat("demo_gind",filters=list(geo=eu_countries$code,indic_de="JAN",lastTimePeriod=1),type="code",time_format = "num") %>%
select(geo,values) %>% rename(pop=values)
# Scientists are measures in Thousands
data <- left_join(sci,pop,by="geo") %>% mutate(scipop = round(sci*1000/pop*1000,0)) %>%
@mschnetzer
mschnetzer / estateprices.r
Last active October 14, 2018 19:15
Baugrundstückspreise nach Bezirken, 2017
# Download XLS, merge sheets and export as csv: http://www.statistik.at/web_de/statistiken/wirtschaft/preise/immobilien_durchschnittspreise/index.html
immodat <- read_csv2("baugrundstueckspreise_2017.csv",skip = 3) %>%
select(iso=B.Nr., preis=starts_with("Euro")) %>% add_row(iso=900,preis=1000) %>%
filter(!is.na(iso), !is.na(preis)) %>% mutate(preis=round(preis,-1)) %>%
mutate(preis=cut(preis,breaks=c(0,50,100,200,500,3000),
labels=c("<50€","50-100€","100-200€","200-500€",">500€")))
source("plotmap.R")
plotbezirke(dataset=immodat,fillvar="preis",wienbezirke=F,colpal=msc_palette[5:1],
library(tidyverse)
library(msmaps)
library(sf)
# Load data
pop <- read_csv2("population.csv") %>% filter(iso<901) %>% select(iso,pop)
quarter <- pop %>% summarise(sum(pop)/4) %>% as.numeric()
quarter <- quarter*c(0:4)
# Load Geodata
@mschnetzer
mschnetzer / wohnkosten.r
Last active November 2, 2018 10:58
Anteil der Ausgaben für Miete am verfügbaren Haushaltseinkommen, 2017 (https://twitter.com/matschnetzer/status/1058312258978308097)
library(tidyverse)
library(msmaps)
library(eurostat)
data <- get_eurostat("ilc_mded02",filters=list(hhtyp="TOTAL",incgrp="TOTAL",time=c("2016","2017")),type="code",time_format="num") %>%
mutate(geo=recode(geo,"UK"="GB","EL"="GR")) %>% select(geo,time,values) %>%
group_by(geo) %>% fill(values) %>% filter(time==2017)
mapdata <- data %>%
mutate(cat = cut(values, breaks = c(0,15,20,25,30,35))) %>% select(geo,cat) %>%
@mschnetzer
mschnetzer / publictransport.r
Last active July 14, 2019 10:36
Benutzung öffentlicher Verkehrsmittel nach Bundesländer (https://twitter.com/matschnetzer/status/1063423205401071618)
#### Code was adapted from https://github.com/ryantimpe/ChartOfTheDay ###
#### H/T to @ryantimpe!
library(tidyverse)
library(rvest)
library(png)
library(msthemes)
df <- tibble(geo=as.factor(c("Wien","Vorarlberg","Salzburg","Steiermark","Niederösterreich","Tirol","Oberösterreich","Kärnten","Burgenland")),
public=c(92,66,61,58,57,55,50,42,36),
library(tidyverse)
library(rdbnomics)
library(scales)
library(ggrepel)
library(msthemes)
unemp <- rdb(ids='OECD/MEI/AUT.LMUNRRTT.STSA.Q')
unemp$draw <- 1
unemp <- unemp %>% mutate(label = case_when(
value == max(value) ~ 1,