Created
November 30, 2022 22:53
-
-
Save MattCowgill/21ceee08b237a9c4dbefb227653a4674 to your computer and use it in GitHub Desktop.
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(readxl) | |
library(tidyverse) | |
library(ggdirectlabel) | |
library(patchwork) | |
madd_url <- "https://www.rug.nl/ggdc/historicaldevelopment/maddison/data/mpd2020.xlsx" | |
madd_file <- tempfile(fileext = ".xlsx") | |
download.file(madd_url, madd_file, mode = "wb") | |
madd_data <- read_excel(madd_file, sheet = "Full data") | |
oz_arg <- madd_data |> | |
filter(country %in% c("Argentina", | |
"Australia")) |> | |
filter(!is.na(gdppc), | |
year >= 1850) | |
my_theme <- theme_minimal( | |
base_family = "Roboto Condensed", | |
base_size = 18) + | |
theme(axis.title = element_blank(), | |
legend.position = "none", | |
axis.line = element_line(size = 0.25), | |
panel.grid.minor = element_blank(), | |
plot.title.position = "plot", | |
plot.caption.position = "plot", | |
plot.caption = element_text(hjust = 0, | |
size = 9, | |
face = "italic")) | |
plot_level <- oz_arg |> | |
ggplot(aes(x = year, y = gdppc, col = country)) + | |
geom_linepoint(linewidth = 1, | |
size = 18 / .pt) + | |
geom_finallabel(aes(label = paste0(country, "\n", | |
scales::dollar(gdppc, 1))), | |
nudge_x_perc = 3, | |
size = 18 / .pt, | |
family = "Roboto Condensed") + | |
scale_y_continuous(labels = scales::dollar, | |
limits = \(x) c(0, x[2]), | |
expand = expansion(c(0, 0.05))) + | |
scale_x_continuous(expand = expansion(c(0, 0.27)), | |
breaks = c(seq(1800, 2000, 50), | |
max(madd_data$year)), | |
labels = \(x) ifelse(x == 2018, "'18", x)) + | |
labs(subtitle = "Real GDP per capita") + | |
my_theme | |
plot_ratio <- oz_arg |> | |
select(country, year, gdppc) |> | |
pivot_wider(names_from = country, | |
values_from = gdppc) |> | |
mutate(ratio = Argentina / Australia) |> | |
ggplot(aes(x = year, y = ratio)) + | |
geom_line(colour = "#404040", | |
linewidth = 1) + | |
scale_y_continuous(labels = scales::percent, | |
expand = expansion(0.1)) + | |
scale_x_continuous(breaks = c(seq(1800, 2000, 50), | |
max(madd_data$year)), | |
labels = \(x) ifelse(x == 2018, "'18", x)) + | |
my_theme + | |
labs(subtitle = "Argentina's real GDP per capita as a percentage of Australia's") | |
plot_level + | |
plot_ratio + | |
plot_annotation(caption = "Source: Maddison Project database.", | |
theme = my_theme) |
Author
MattCowgill
commented
Nov 30, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment