Skip to content

Instantly share code, notes, and snippets.

@mschnetzer
mschnetzer / passengergrowth.r
Last active December 7, 2018 08:30
Wachstum beförderter Fluggäste, 2007-2017 (https://twitter.com/matschnetzer/status/1070958511872466944)
library(tidyverse)
library(eurostat)
library(grid)
library(png)
library(msthemes)
# Load data
data <- get_eurostat("avia_paoc", filters = list(schedule="TOT",time = c("2007","2017"),tra_cov="TOTAL",tra_meas="PAS_CRD",unit="PAS"), time_format = "num")
# Calculate growth 2007-2017
@mschnetzer
mschnetzer / selfassessment.r
Last active December 31, 2019 10:33
Current and estimated position in the net wealth distribution (https://twitter.com/matschnetzer/status/1090954828631732224)
library(tidyverse)
library(survey)
library(msthemes)
library(gganimate)
# Load HFCS and Non-core data
load("hfcs2014AT.rda")
load("Noncore AT/non-core-at.rda")
# Calculate estimated decile with mean from multiple imputation data
@mschnetzer
mschnetzer / taxcompliance.R
Last active May 11, 2019 13:29
Tax compliance gaps in the European Union, 2015 (https://twitter.com/matschnetzer/status/1093041603286052864)
library(tidyverse)
library(pdftools)
library(msmaps)
library(countrycode)
# Link to source document
url <- "https://www.socialistsanddemocrats.eu/sites/default/files/2019-01/the_european_tax_gap_en_190123.pdf"
rawpdf <- pdf_text(url)
rawpdf <- rawpdf[9] # Table of interest is on page 9
library(tidyverse)
library(msthemes)
library(RColorBrewer)
library(gganimate)
# Get data from http://www.zamg.ac.at/histalp/dataset/station/csv.php
data <- read_csv2("HISTALP_AT_WIE_T01_1760_2020.csv",skip = 13)
data <- data %>% mutate_at(vars("jan-dec"),funs(temp=.*0.1)) %>% select(year,temp) %>% filter(year %in% c(1775:2018))
data$draw <- 1
library(tidyverse)
library(eurostat)
library(countrycode)
library(msthemes)
library(lubridate)
library(png)
library(jpeg)
library(grid)
# Load tax rate data (https://ec.europa.eu/taxation_customs/sites/taxation/files/taxation_trends_report_2018_statutory_rates.xlsx)
@mschnetzer
mschnetzer / gundeaths.r
Last active May 11, 2019 13:26
Firearm deaths in the United States 1999-2017 (https://twitter.com/matschnetzer/status/1119168161373413381)
library(tidyverse)
library(grid)
library(png)
library(msthemes)
library(gganimate)
gun <- readPNG("gun.png")
# Download data from https://wonder.cdc.gov/controller/saved/D76/D48F344
gundf <- read.table(file = "Firearm deaths by intent, 1999-2017.txt", header = T, fill=T, sep="\t") %>% filter(Notes=="Total", !is.na(Year)) %>% select(Year,Deaths)
library(tidyverse)
library(rdbnomics)
library(gganimate)
library(msthemes)
library(png)
library(grid)
wsdata <- rdb("AMECO","ALCD2",dimensions=list(geo = c("aut","deu","d-w","ita","fra","esp"))) %>%
select(geo,original_period,value) %>% na.omit %>%
mutate(year= as.Date(original_period,"%Y")) %>%
@mschnetzer
mschnetzer / ustaxavoid.r
Last active May 17, 2019 14:04
US Companies Avoiding All Federal Income Taxes in 2018 (https://twitter.com/matschnetzer/status/1129387087529238528)
library(tidyverse)
library(pdftools)
library(msthemes)
# Link to source document
url <- "https://itep.org/wp-content/uploads/notadime-rgb.pdf"
rawpdf <- pdf_text(url)
# Split lines at \n and delete the whitespaces at the beginning
@mschnetzer
mschnetzer / ibiza.r
Last active May 21, 2019 15:46
Textanalyse der Pressekonferenzen Kurz und Strache zum #ibizagate (https://twitter.com/matschnetzer/status/1130862027696742406)
library(tidytext)
library(tm)
library(tidyverse)
library(ggforce)
library(msthemes)
library(rvest)
strache <- read_html("https://neuwal.com/transkript/20190518-pressekonferenz-heinz-christian-strache.php") %>%
html_nodes(".antwort") %>%
html_text()
@mschnetzer
mschnetzer / timeuse.r
Last active June 13, 2019 17:51
Waffle Plot der geschlechtsspezifischen Aufteilung von bezahlter und unbezahlter Arbeitszeit (https://twitter.com/matschnetzer/status/1139058925691707392)
library(tidyverse)
library(msthemes)
library(waffle)
faclevel <- c("Berufliche Tätigkeiten","Haushaltsführung","Kinderbetreuung","Betreuung Erwachsener","Freiwilligenarbeit")
# Data from http://www.statistik.at/wcm/idc/idcplg?IdcService=GET_PDF_FILE&RevisionSelectionMethod=LatestReleased&dDocName=052108
tibble(labels=factor(faclevel,levels=faclevel),
'Männer' = c(111.0,49.7,7.7,0.6,5.5),
'Frauen'=c(71.4,99.2,17.5,1.1,5.2)) -> df