# 7.5.d - 7.5.h: Contour plots
# Make predictions at all combinations of both continuous IVs (one year at a time,
# which needs much less memory than one call for all 676 combinations)
pr4 <- bind_rows(lapply(1:52, function(y) {
avg_predictions(samemod, by = c("conviewSS", "year1972"), vcov = FALSE,
newdata = datagrid(conviewSS = seq(1, 7, .5), year1972 = y,
grid_type = "counterfactual"))
}))
# 7.5.g - Ordinal color scheme viridis (the default)
ggplot(pr4, aes(x = year1972, y = conviewSS, z = estimate)) +
geom_contour_filled(breaks = seq(0, 1, .05)) +
scale_fill_viridis_d(direction = -1, drop = FALSE) +
scale_x_continuous(breaks = c(2, 8, 18, 28, 38, 48),
labels = c(1974, 1980, 1990, 2000, 2010, 2020), expand = c(0, 0)) +
scale_y_continuous(breaks = c(1, 2.5, 4, 5.5, 7), labels = c("Very\nliberal",
"Liberal", "Middle", "Conservative", "Very\nconservative"), expand = c(0, 0)) +
labs(title = "[7.5.g] Predicted probability of thinking same-sex relationships are acceptable",
subtitle = "Interaction: Political beliefs X survey year",
x = NULL, y = NULL, fill = "Pr(Same-Sex\nRelationships OK)")