# Aggregate to treatment group level by month
trends_data <- outcome_wide %>%
group_by(year_month, date, treated, post) %>%
summarise(
NO2_mean = mean(NO2_mean, na.rm = TRUE),
PM25_mean = mean(PM25_mean, na.rm = TRUE),
.groups = "drop"
) %>%
mutate(
group = ifelse(treated == 1, "Treated Districts", "Control Districts")
)
# NO2 trends
p1 <- ggplot(trends_data, aes(x = date, y = NO2_mean, color = group, group = group)) +
geom_line(linewidth = 1) +
geom_vline(xintercept = treatment_date, linetype = "dashed", color = "red", linewidth = 1) +
annotate("text", x = treatment_date, y = max(trends_data$NO2_mean, na.rm = TRUE),
label = "M7 Opening\n(Oct 2020)", hjust = -0.1, color = "red", size = 3.5) +
scale_color_manual(values = c("Treated Districts" = "#E41A1C",
"Control Districts" = "#377EB8")) +
labs(
title = "NO₂ Concentration Over Time",
subtitle = "Treated vs Control Districts",
x = "Date",
y = "NO₂ (µg/m³)",
color = "Group"
) +
theme_minimal(base_size = 12) +
theme(
legend.position = "bottom",
plot.title = element_text(face = "bold")
)
# PM2.5 trends
p2 <- ggplot(trends_data, aes(x = date, y = PM25_mean, color = group, group = group)) +
geom_line(linewidth = 1) +
geom_vline(xintercept = treatment_date, linetype = "dashed", color = "red", linewidth = 1) +
annotate("text", x = treatment_date, y = max(trends_data$PM25_mean, na.rm = TRUE),
label = "M7 Opening\n(Oct 2020)", hjust = -0.1, color = "red", size = 3.5) +
scale_color_manual(values = c("Treated Districts" = "#E41A1C",
"Control Districts" = "#377EB8")) +
labs(
title = "PM2.5 Concentration Over Time",
subtitle = "Treated vs Control Districts",
x = "Date",
y = "PM2.5 (µg/m³)",
color = "Group"
) +
theme_minimal(base_size = 12) +
theme(
legend.position = "bottom",
plot.title = element_text(face = "bold")
)
p1 / p2