# Interactive K-shaped spending chart by income quartile
interactive_daily_spending <- df_k_plot %>%
ggplot(aes(date, monthly_spending, color = income_group)) +
geom_rect(
data = recession_df, inherit.aes = FALSE,
aes(xmin = start, xmax = end, ymin = ymin, ymax = ymax),
fill = "grey", alpha = 0.3
) +
annotate("text",
x = as.Date("2020-03-15"),
y = max(df_k_plot$monthly_spending, na.rm = TRUE) * 0.95,
label = "Recession", color = "black", fontface = "italic", size = 3.5
) +
geom_line(linewidth = 1, alpha = 0.8) +
geom_point(size = 2) +
scale_x_date(date_labels = "%b %Y", date_breaks = "3 months") +
labs(
title = "K-Shaped Economic Recovery",
subtitle = "Daily Consumer Spending Index by Income Quartile",
x = "Date", y = "Daily Spending Index", color = "Income Group",
caption = "Source: Affinity Solutions via Opportunity Insights Economic Tracker"
) +
theme_economist() + scale_colour_economist() +
theme(
axis.text.x = element_text(angle = 45, hjust = 1, size = 10),
plot.title = element_text(face = "bold", size = 16),
plot.subtitle = element_text(size = 12),
legend.position = "bottom",
legend.title = element_text(size = 10),
legend.text = element_text(size = 9)
)
ggplotly(interactive_daily_spending) %>%
layout(legend = list(orientation = "h", x = 0.5, xanchor = "center", y = -0.3))
# Total spending across all categories
plot_spend_all %>%
ggplot(aes(date, monthly_spending, color = income_group)) +
geom_rect(
data = recession_df, inherit.aes = FALSE,
aes(xmin = start, xmax = end, ymin = ymin, ymax = ymax),
fill = "grey", alpha = 0.3
) +
geom_hline(yintercept = 0, color = "black", linewidth = 0.4) +
geom_line(linewidth = 1.2, alpha = 0.8) +
geom_point(size = 1.8) +
scale_x_date(date_labels = "%b %Y", date_breaks = "3 months") +
labs(
title = "K-Shaped Economy: All Spending",
x = "Date", y = "All Spending Index", color = "Income Group",
caption = "Source: Affinity Solutions via Opportunity Insights Economic Tracker"
) +
###horizontal label acting wonky, alter later
theme_economist() + scale_colour_economist() +
theme(
axis.text.x = element_text(angle = 45, hjust = 1, vjust = 1),
plot.title = element_text(face = "bold", size = 16),
legend.position = "bottom",
legend.text = element_text(size = 9)
)
# Employment recovery diverges sharply by wage quartile post-recession
employment_plot <- ggplot(date_emp, aes(date_monthly, avg_employment_index, color = wage_group)) +
geom_rect(
data = recession_df, inherit.aes = FALSE,
aes(xmin = start, xmax = end, ymin = ymin, ymax = ymax),
fill = "grey", alpha = 0.3
) +
geom_hline(yintercept = 0, linetype = "solid", color = "black", linewidth = 0.5) +
geom_line(linewidth = 1, alpha = 0.8) +
geom_point(size = 1.5) +
scale_x_date(date_labels = "%b %Y", date_breaks = "3 months") +
labs(
title = "Monthly Employment Recovery by Wage Quartile",
x = "Date", y = "Employment Level (Indexed, Jan 2020 = 0)",
color = "Wage Group",
caption = "Source: Affinity Solutions via Opportunity Insights Economic Tracker"
) +
theme_economist() + scale_colour_economist() +
theme(
legend.position = "bottom",
legend.title = element_text(size = 8),
legend.text = element_text(size = 7),
legend.key.size = unit(0.5, "lines"),
axis.text.x = element_text(angle = 45, hjust = 1, vjust = 1),
plot.title = element_text(face = "bold", size = 16)
)
ggplotly(employment_plot) %>%
layout(legend = list(orientation = "h", x = 0.5, xanchor = "center", y = -0.3))
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.