titanic_summary <- titanic %>%
group_by(d, sex_label, age_label) %>%
summarize(n = n(), survival = mean(survived), .groups = "drop") %>%
mutate(class_label = ifelse(d == 1, "First Class", "Other Classes"))
p1 <- titanic %>%
group_by(d) %>%
summarize(pct_female = mean(sex_label == "Female"), .groups = "drop") %>%
mutate(class_label = ifelse(d == 1, "First Class", "Other Classes")) %>%
ggplot(aes(x = class_label, y = pct_female, fill = class_label)) +
geom_col(width = 0.6, show.legend = FALSE) +
geom_text(aes(label = scales::percent(pct_female, accuracy = 1)),
vjust = -0.5, size = 5, fontface = "bold") +
scale_fill_manual(values = c(warm_gold, slate_gray)) +
scale_y_continuous(labels = scales::percent, limits = c(0, 0.8), expand = expansion(mult = c(0, 0.08))) +
labs(title = "% Female by Class", x = "", y = "") +
theme_health_econ(base_size = 14)
p2 <- titanic %>%
group_by(d) %>%
summarize(pct_adult = mean(age_label == "Adult"), .groups = "drop") %>%
mutate(class_label = ifelse(d == 1, "First Class", "Other Classes")) %>%
ggplot(aes(x = class_label, y = pct_adult, fill = class_label)) +
geom_col(width = 0.6, show.legend = FALSE) +
geom_text(aes(label = scales::percent(pct_adult, accuracy = 1)),
vjust = -0.5, size = 5, fontface = "bold") +
scale_fill_manual(values = c(warm_gold, slate_gray)) +
scale_y_continuous(labels = scales::percent, limits = c(0, 1), expand = expansion(mult = c(0, 0.08))) +
labs(title = "% Adult by Class", x = "", y = "") +
theme_health_econ(base_size = 14)
p3 <- titanic %>%
group_by(sex_label, age_label) %>%
summarize(survival = mean(survived), .groups = "drop") %>%
ggplot(aes(x = interaction(sex_label, age_label), y = survival,
fill = sex_label)) +
geom_col(width = 0.6) +
geom_text(aes(label = scales::percent(survival, accuracy = 1)),
vjust = -0.5, size = 4, fontface = "bold") +
scale_fill_manual(values = c(accent_coral, secondary_teal), name = "") +
scale_y_continuous(labels = scales::percent, limits = c(0, 1), expand = expansion(mult = c(0, 0.08))) +
labs(title = "Survival by Sex & Age", x = "", y = "") +
theme_health_econ(base_size = 14) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
p1 + p2 + p3