Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Finland’s mandatory pension contributions - http://ilari.scheinin.fi/finlands-mandatory-pension-contributions/
library(pxweb)
library(dplyr)
library(ggplot2)
api <- "http://pxnet2.stat.fi/PXWeb/api/v1/"
pension_fees <- get_pxweb_data(
url=paste0(api, "en/StatFin/jul/vermak/102_vermak_tau_120.px"),
dims=list(Verolaji = c("D61111_TYO", "D61121_TYO"), Sektori = c("S13141"),
Tieto = c("Suhde1"), Vuosi = c("*")),
clean=TRUE) %>%
tbl_df() %>%
select(-Sector, -Data) %>%
transmute(
year=as.integer(as.character(Year)),
contributor=gsub("^.*(mploye[re]).*$", "e\\1", `Tax category`),
percentage=values
)
png("finland-pension-contributions.png",
width=297, height=210, units="mm", res=150)
ggplot(pension_fees, aes(year, percentage, fill=contributor)) +
geom_area(position="stack") +
scale_fill_manual(values=c("#ffffff", "#18447e")) +
theme(text=element_text(size=16),
legend.position="bottom", legend.title=element_blank(),
legend.background=element_rect(fill="#9ecae1"),
legend.key=element_rect(fill=NA, color=NA),
panel.background=element_rect(fill="#9ecae1"),
plot.background=element_rect(fill="#9ecae1")) +
labs(title="Finland's mandatory pension contributions as percent of GDP",
x="year", y="percent of GDP") +
annotate("text", x=1975.25, y=9.875, hjust=0, vjust=1,
label="By: Ilari Scheinin\nSource: Statistics Finland\nLicense: CC BY")
dev.off()
# 2016-03-09
# Ilari Scheinin
# CC BY
# EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment