Last active
October 22, 2022 06:57
-
-
Save MattCowgill/85483380376e9acd148e0735eb56698a to your computer and use it in GitHub Desktop.
Recreate an RBA chart of inflation in key locations
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(OECD) | |
library(tidyverse) | |
library(lubridate) | |
library(countrycode) | |
oecd_cpi_raw <- get_dataset("PRICES_CPI", | |
"AUS+CAN+JPN+GBR+USA+EA19.CPALTT01.GY.Q+M") | |
oecd_cpi <- oecd_cpi_raw |> | |
janitor::clean_names() |> | |
mutate(date = if_else(frequency == "Q", | |
yq(time), | |
ym(time)), | |
obs_value = as.numeric(obs_value)) |> | |
mutate(country = countrycode(location, "wb", "country.name"), | |
country = if_else(location == "EA19", "Euro area", country), | |
country = factor(country, levels = c("United States", | |
"Euro area", | |
"United Kingdom", | |
"Canada", | |
"Japan", | |
"Australia"))) | |
oecd_cpi |> | |
filter(date >= ymd("2012-01-01")) |> | |
ggplot(aes(x = date, y = obs_value)) + | |
geom_hline(yintercept = 0) + | |
geom_line(colour = "#20A8E2", | |
size = 1.25) + | |
geom_text(data = ~group_by(., country) |> summarise(date = mean(date)), | |
aes(label = country), | |
size = 18 / .pt, | |
y = 11) + | |
facet_wrap(~country) + | |
scale_x_date(limits = \(x) c(x[1], ymd("2023-01-01")), | |
date_breaks = "1 year", | |
labels = \(x) { | |
ifelse(!year(x) %in% c(2016, 2022), | |
"", | |
format(x, "%Y")) | |
} | |
) + | |
scale_y_continuous(limits = c(-2, 12), | |
breaks = seq(-2, 12, 2), | |
expand = expansion(0), | |
labels = c('', seq(0, 10, 2), "%")) + | |
theme_minimal(base_family = "sans", | |
base_size = 18) + | |
theme(strip.text = element_blank(), | |
panel.grid.minor = element_blank(), | |
axis.ticks.x = element_line(), | |
panel.grid.major.x = element_blank(), | |
axis.title = element_blank(), | |
plot.title = element_text(face = "bold", | |
hjust = 0.5), | |
plot.subtitle = element_text(hjust = 0.5), | |
plot.caption = element_text(size = 10, hjust = 0), | |
panel.border = element_rect(fill = NA)) + | |
labs(title = "Headline Consumer Price Inflation", | |
subtitle = "Year-ended", | |
caption = "Source: OECD.") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment