Created
November 6, 2018 10:02
-
-
Save expersso/302ed462a80d169601cf8e740b2e2278 to your computer and use it in GitHub Desktop.
Expenditure-side real GDP at chained PPPs
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(tidyverse) | |
library(scales) | |
library(ggrepel) | |
library(patchwork) | |
library(ggthemes) | |
library(pwt9) | |
years <- c(1955, 2014) | |
pwt9.0 <- pwt9.0 %>% | |
mutate(isocode = as.character(isocode)) | |
top8 <- pwt9.0 %>% | |
group_by(year) %>% | |
arrange(desc(rgdpe)) %>% | |
slice(1:8) %>% | |
pull(isocode) %>% | |
unique() | |
colors <- c(few_pal()(7), colorblind_pal()(6)[-5]) %>% | |
set_names(top8) | |
df_plot <- pwt9.0 %>% | |
filter(isocode %in% top8) | |
df_lbls <- df_plot %>% | |
filter(year %in% years) | |
p_time <- ggplot(df_plot, aes(x = year, y = rgdpe / 1e3, color = isocode, linetype = isocode)) + | |
geom_line() + | |
ggrepel::geom_text_repel(aes(label = isocode), df_lbls, size = 3, fontface = "bold", hjust = "outward") + | |
scale_y_log10(breaks = pretty_breaks(5), labels = comma) + | |
scale_x_continuous(breaks = pretty_breaks(10)) + | |
scale_color_manual(values = colors) + | |
theme_minimal() + | |
theme(legend.position = "none") + | |
labs( | |
x = NULL, y = NULL, | |
title = "Expenditure-side real GDP at chained PPPs", | |
subtitle = "billion 2011 USD" | |
) | |
df_cols <- pwt9.0 %>% | |
filter(year %in% years) %>% | |
select(year, isocode, rgdpe) %>% | |
group_by(year) %>% | |
arrange(desc(rgdpe)) %>% | |
slice(1:8) | |
p_col <- function(yr) { | |
df_cols %>% | |
filter(year == yr) %>% | |
ggplot(aes(x = reorder(isocode, rgdpe), y = rgdpe / 1e3, fill = isocode)) + | |
geom_col(show.legend = FALSE) + | |
coord_flip() + | |
scale_fill_manual(values = colors) + | |
scale_y_continuous(labels = comma) + | |
theme_minimal() + | |
labs(x = NULL, y = NULL, subtitle = yr) | |
} | |
p_time / (p_col(1955) + p_col(2014)) + | |
plot_layout(nrow = 2, heights = c(.75, .25)) + | |
plot_annotation(caption = "Source: Penn World Tables 9.0") |
Author
expersso
commented
Nov 6, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment