Last active
August 14, 2018 16:38
-
-
Save mschnetzer/7f8cb66593d676496e88e6384b626744 to your computer and use it in GitHub Desktop.
Leistungsbilanzsalden EU-Länder (https://twitter.com/matschnetzer/status/984797548807417857)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(eurostat) | |
library(tidyverse) | |
library(stringr) | |
library(lubridate) | |
library(ggridges) | |
library(viridis) | |
library(ggthemes) | |
# Only EU countries | |
cty = eu_countries$code | |
# Get data | |
data <- get_eurostat("bop_gdp6_q",filters=list(geo=cty,bop_item="CA",stk_flow="BAL",partner="WRL_REST",s_adj="NSA",unit="PC_GDP"),type="code",time_format="raw") %>% | |
full_join(., eu_countries, by=c("geo"="code")) %>% select(name,time,values) | |
# Edit time variable (thanks to @GabPa for advice) | |
ca <- data %>% filter(str_detect(time,"Q\\d$")) %>% mutate(year=format(parse_date_time(time,"yq"),"%Y")) %>% na.omit() | |
# Choose time frame (e.g. after Euro) | |
catf <- ca %>% filter(year>=2007) %>% mutate(labgeo=name) | |
# Label countries with first and last available year | |
cafull <- ca %>% group_by(name) %>% mutate(labgeo = sprintf("%s (%s-%s)", name, min(year), max(year))) | |
# Plot catf or catfull | |
ggplot(catf, aes(x = values, y = reorder(labgeo,values), fill = ..x..)) + | |
geom_density_ridges_gradient(scale = 3, rel_min_height = 0.01) + | |
scale_fill_viridis(name = " ", option = "C") + | |
geom_vline(xintercept = 0) + | |
labs(title = "Leistungsbilanzsalden der EU-Länder ab 2007", y="", x="", | |
subtitle= "Quartalsdaten, in % des BIP", | |
caption = "Quelle: EUROSTAT. Grafik: M. Schnetzer") + | |
theme_minimal() + | |
ggsave(filename = "currentaccount.png",scale=2,width=6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment