Created
November 12, 2022 04:10
-
-
Save MattCowgill/b6a4172d892055a0042a479bc2578ed6 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(tidyverse) | |
library(readabs) | |
vac_raw <- read_abs_series("A85389466F") | |
ur_raw <- read_abs_series("A84423050A") | |
ur <- ur_raw |> | |
mutate(value = slider::slide_mean(value, before = 2L)) |> | |
select(date, ur = value) | |
df_wide <- vac_raw |> | |
select(date, vac = value) |> | |
left_join(ur, by = "date") |> | |
mutate(period = if_else(date < ymd("2020-03-01"), | |
"Pre-pandemic", | |
"Pandemic")) |> | |
filter(!is.na(vac)) | |
pre_covid_mod <- df_wide |> | |
filter(period == "Pre-pandemic") |> | |
lm(vac ~ ur + I(ur ^ 2), data = _) | |
latest <- df_wide |> | |
filter(date == max(date)) | |
latest_predicted <- predict(pre_covid_mod, newdata = latest) | |
y_offset <- latest$vac - latest_predicted | |
add_perc <- function(x) paste0(x, "%") | |
df_wide |> | |
ggplot(aes(x = ur, | |
y = vac, | |
col = period)) + | |
geom_smooth(data = ~filter(., period == "Pre-pandemic"), | |
method = "lm", | |
se = FALSE, | |
fullrange = T, | |
formula = y ~ x + I(x ^ 2)) + | |
geom_smooth(data = ~filter(., period == "Pre-pandemic"), | |
method = "lm", | |
se = FALSE, | |
linetype = 2, | |
fullrange = T, | |
aes(y = vac + y_offset), | |
formula = y ~ x + I(x ^ 2)) + | |
geom_point() + | |
geom_point(data = latest, | |
colour = "black", | |
size = 3) + | |
geom_text(data = latest, | |
aes(label = format(date, "%B %Y")), | |
colour = "black", | |
hjust = 0, | |
family = "Roboto Condensed", | |
nudge_x = 0.25) + | |
hrbrthemes::theme_ipsum_rc() + | |
scale_colour_manual(values = c("red", "blue")) + | |
scale_y_continuous(labels = add_perc, | |
expand = expansion(0), | |
limits = \(x) c(0, max(5, x[2]))) + | |
scale_x_continuous(labels = add_perc, | |
limits = c(0, 10), | |
expand = expansion(0), | |
breaks = seq(0, 10, 2)) + | |
theme(legend.position = c(0.9, 0.9), | |
legend.title = element_blank(), | |
panel.grid.minor = element_blank()) + | |
labs(x = "Unemployment rate", | |
y = "Vacany rate") | |
ggsave("bev_mong.png", | |
bg = "white", | |
width = 16, | |
height = 12, | |
units = "cm") |
Author
MattCowgill
commented
Nov 12, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment