Skip to content

Instantly share code, notes, and snippets.

@mschnetzer
Last active December 7, 2018 08:30
Show Gist options
  • Save mschnetzer/4f7dd3ad9a6e4bf8fbd213d19a8486ee to your computer and use it in GitHub Desktop.
Save mschnetzer/4f7dd3ad9a6e4bf8fbd213d19a8486ee to your computer and use it in GitHub Desktop.
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
pas <- data %>% select(geo,time,values) %>% group_by(geo) %>% mutate(growth = values/lag(values)*100-100) %>% na.omit() %>% arrange(growth)
# Select 7 countries with highest passenger numbers and Austria
pas <- pas %>% filter(geo %in% c("EU27","UK","AT","DE","ES","FR","IT","NL")) %>% mutate(size=10, labcty = recode(geo,"AT"="Österreich", "EU27"="EU-27","ES"="Spanien","FR"="Frankreich","IT"="Italien","UK" = "Großbritannien","DE" = "Deutschland","NL"="Niederlande"))
pas$index <- as.numeric(1:nrow(pas))
# Load plane png
plane <- rasterGrob(readPNG("plane.png"))
ggplot(data=pas,aes(x=index,y=growth)) + geom_bar(stat="identity",width = 0.2,fill=msc_palette[4]) +
mapply(function(x, y, i) {
annotation_custom(plane, xmin = x-0.6*pas$size[i], xmax = x+0.635*pas$size[i],
ymin = y-0.6*pas$size[i], ymax = y+0.6*pas$size[i])},
pas$index, pas$growth, seq_len(nrow(pas))) +
geom_text(aes(x=index+0.25, y=growth-7.5, label=paste0("+ ",round(growth,0),"%")), colour="black", fontface="bold", size=2.5) +
geom_text(aes(x=index+0.25, y=0.3, label=paste0("2017: ",round(values/1000000,0)," Mio. Fluggäste")), size=1.7,hjust = "left") +
coord_flip() + theme_ms(alttf = T, grid=F) + theme(axis.text.x = element_blank()) +
scale_y_continuous(expand = c(0, 0), limits = c(0, 1.2 * max(pas$growth))) +
scale_x_continuous(breaks=c(1:nrow(pas)), labels=pas$labcty) +
labs(x = "", y = "", title = "Abgehobenes Wachstum", subtitle="Anstieg der beförderten Flugpassagiere, 2007-2017", caption="Daten: Eurostat. Grafik: @matschnetzer") +
ggsave("planegrowth.png", dpi=300)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment