Skip to content

Instantly share code, notes, and snippets.

@mschnetzer
Last active April 12, 2019 08:59
Show Gist options
  • Save mschnetzer/ddbabf327bd8c404c86a9086ce6117de to your computer and use it in GitHub Desktop.
Save mschnetzer/ddbabf327bd8c404c86a9086ce6117de to your computer and use it in GitHub Desktop.
Corporate Income Tax rates, 1995-2018 (https://twitter.com/matschnetzer/status/1116626740346908674)
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)
rates <- readxl::read_xlsx("taxation_trends_report_2018_statutory_rates.xlsx",
sheet = "CIT rates", skip = 4, n_max = 28)
rates <- rates %>% gather(year,taxrate,`1995`:`2018`) %>% rename(country = "...1") %>% mutate(year=as.numeric(year), country=fct_recode(country,"Czechia"="Czech Republic"))
# Load GDP data from Eurostat
eudat <- get_eurostat("nama_10_gdp",filters = list(na_item="B1GQ", unit="CP_MEUR",time=1995:2018), time_format = "num") %>% select(geo,time,values) %>% label_eurostat() %>%
mutate(geo=fct_recode(geo, "Germany"="Germany (until 1990 former territory of the FRG)")) %>% rename("gdp"="values")
# Join datasets
taxdat <- rates %>% left_join(., eudat, by=c("country"="geo","year"="time")) %>% group_by(year) %>% mutate(gdpshare = gdp/sum(gdp)*100)
# Add German country names
taxdat <- left_join(taxdat, codelist %>% select(country.name.en,country.name.de), by=c("country"="country.name.en"))
# Calculate mean and GDP-weighted mean
meanrate <- taxdat %>% group_by(year) %>% summarise(taxrate = mean(taxrate))
wmeanrate <- taxdat %>% group_by(year) %>% summarise(taxrate = weighted.mean(taxrate,gdpshare))
# Load paper image
image <- readJPEG("paper.jpg")
skyline <- readPNG("skyline.png")
### Deutsch
ltit = c("Körperschaftssteuern in der Europäischen Union")
lsub = c("Regelsteuertarife in den 28 EU-Staaten, 1995-2018")
lcap = c("Eurostat-Definition: Top statutory corporate income tax rates (including surcharges). \nDaten: Eurostat. Grafik: @matschnetzer")
llabs = c("BIP-Gewichteter Durchschnitt", "Durchschnitt")
### English
# ltit = c("Corporate income taxes in the European Union")
# lsub = c("Statutory tax rates in the EU-28 states, 1995-2018")
# lcap = c("Eurostat-Definition: Top statutory corporate income tax rates (including surcharges). \nData: Eurostat. Figure: @matschnetzer")
#llabs = c("GDP-weighted average", "Average")
plot <- ggplot(taxdat, aes(x=year,y=taxrate)) +
geom_line(aes(group=country), alpha=0.4) +
geom_line(data = meanrate, aes(group=""), color=msc_palette[1], size=1.4, alpha=1) +
geom_line(data = wmeanrate, aes(group=""), colour=msd_palette[3], size=1.4, alpha=1) +
geom_curve(aes(x=2006,xend=2007,y=wmeanrate$taxrate[wmeanrate$year==2006],yend=44),
curvature = 0.1, color=msd_palette[3], ncp=8, size=0.2,
arrow=arrow(length=unit(0.02, "npc"), ends="first", type="closed")) +
annotate(geom="label", x=2007, y=44, label=llabs[1],
color=msd_palette[3], size=3, hjust=0.5, family="Humor Sans") +
geom_curve(aes(x=2002,xend=2000,
y=meanrate$taxrate[meanrate$year==2002],yend=22),
curvature = -0.2, color=msc_palette[1], ncp=8, size=0.2,
arrow=arrow(length=unit(0.02, "npc"), ends="first", type="closed")) +
annotate(geom="label", x=2000, y=22, label=llabs[2],
color=msc_palette[1], size=3, hjust=1, family="Humor Sans") +
theme_ms(grid=F) +
scale_y_continuous(labels = function(x) paste0(x, "%")) +
labs(x="",y="",title=ltit, subtitle=lsub, caption=lcap) +
theme(axis.text.y = element_text(margin = margin(r = -15)),
text = element_text(family="Humor Sans", size=10),
plot.title = element_text(family="Homemade Apple",size=18,color="darkblue",margin = margin(b=2)),
axis.text = element_text(size=10),
plot.caption = element_text(size=7,color="gray20",hjust=0.9),
plot.subtitle = element_text(size=10,color="darkblue"))
png("taxrates.png", width=8, height=4, res=300, units = "in")
grid.draw(gList(rasterGrob(image, width = unit(1,"npc"), height = unit(1,"npc")),
rasterGrob(skyline, x = unit(0.5,"npc"), y=unit(0.4, "npc"),
width = unit(1,"npc"), height = unit(1,"npc")),
ggplotGrob(plot)))
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment