-
-
Save ryanburge/7723afab92372a0e57e81202a8a29f02 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| gg1 <- gss %>% | |
| filter(year <= 2018) %>% | |
| mutate(divorce = frcode(divlaw == 1 ~ "Easier", | |
| divlaw == 3 ~ "Stay As Is", | |
| divlaw == 2 ~ "More Difficult")) %>% | |
| group_by(year) %>% | |
| ct(divorce, wt = wtssall, show_na = FALSE) | |
| gg2 <- gss %>% | |
| filter(year > 2020) %>% | |
| mutate(divorce = frcode(divlaw == 1 ~ "Easier", | |
| divlaw == 3 ~ "Stay As Is", | |
| divlaw == 2 ~ "More Difficult")) %>% | |
| group_by(year) %>% | |
| ct(divorce, wt = wtssnrps, show_na = FALSE) | |
| both <- bind_rows(gg1, gg2) | |
| both %>% | |
| ggplot(., aes(x = year, y = pct, color = divorce, group = divorce)) + | |
| geom_point(stroke = 1, shape = 21, fill = 'white') + | |
| geom_labelsmooth(aes(label = divorce), method = "loess", formula = y ~ x, family = "font", linewidth = 1, text_smoothing = 30, size = 6, linewidth = 1, boxlinewidth = 0.3, hjust = .25) + | |
| theme_rb() + | |
| scale_color_manual(values = c( | |
| "Easier" = "#1b9e77", # Teal Green | |
| "Stay As Is" = "#7570b3", # Purple | |
| "More Difficult" = "#d95f02" # Orange | |
| )) + | |
| scale_y_continuous(labels = percent, limits = c(0, .60)) + | |
| labs(x = "", y = "", title = "Should divorce in this country be easier or more difficult to obtain than it is now?", caption = "@ryanburge + @religiondata | General Social Survey, 1974-2024") | |
| save("divorce_gss24.png") | |
| aa1 <- gss %>% | |
| filter(year <= 2018) %>% | |
| mutate(birthyr = year - age) %>% | |
| mutate(cohorts = frcode(birthyr >= 1940 & birthyr <= 1944 ~ "1940-1944", | |
| birthyr >= 1945 & birthyr <= 1949 ~ "1945-1949", | |
| birthyr >= 1950 & birthyr <= 1954 ~ "1950-1954", | |
| birthyr >= 1955 & birthyr <= 1959 ~ "1955-1959", | |
| birthyr >= 1960 & birthyr <= 1964 ~ "1960-1964", | |
| birthyr >= 1965 & birthyr <= 1969 ~ "1965-1969", | |
| birthyr >= 1970 & birthyr <= 1974 ~ "1970-1974", | |
| birthyr >= 1975 & birthyr <= 1979 ~ "1975-1979", | |
| birthyr >= 1980 & birthyr <= 1984 ~ "1980-1984", | |
| birthyr >= 1985 & birthyr <= 1989 ~ "1985-1989", | |
| birthyr >= 1990 & birthyr <= 1994 ~ "1990-1994", | |
| birthyr >= 1995 & birthyr <= 2000 ~ "1995-2000")) %>% | |
| mutate(divorce = case_when(divlaw == 1 ~ 1, | |
| divlaw == 2 | divlaw == 3 ~ 0)) %>% | |
| group_by(cohorts, year) %>% | |
| mean_ci(divorce, wt = wtssall, ci = .84) | |
| aa2 <- gss %>% | |
| filter(year > 2019) %>% | |
| mutate(birthyr = year - age) %>% | |
| mutate(cohorts = frcode(birthyr >= 1940 & birthyr <= 1944 ~ "1940-1944", | |
| birthyr >= 1945 & birthyr <= 1949 ~ "1945-1949", | |
| birthyr >= 1950 & birthyr <= 1954 ~ "1950-1954", | |
| birthyr >= 1955 & birthyr <= 1959 ~ "1955-1959", | |
| birthyr >= 1960 & birthyr <= 1964 ~ "1960-1964", | |
| birthyr >= 1965 & birthyr <= 1969 ~ "1965-1969", | |
| birthyr >= 1970 & birthyr <= 1974 ~ "1970-1974", | |
| birthyr >= 1975 & birthyr <= 1979 ~ "1975-1979", | |
| birthyr >= 1980 & birthyr <= 1984 ~ "1980-1984", | |
| birthyr >= 1985 & birthyr <= 1989 ~ "1985-1989", | |
| birthyr >= 1990 & birthyr <= 1994 ~ "1990-1994", | |
| birthyr >= 1995 & birthyr <= 2000 ~ "1995-2000")) %>% | |
| mutate(divorce = case_when(divlaw == 1 ~ 1, | |
| divlaw == 2 | divlaw == 3 ~ 0)) %>% | |
| group_by(cohorts, year) %>% | |
| mean_ci(divorce, wt = wtssnrps, ci = .84) | |
| all_years <- sort(unique(c(aa1$year, aa2$year))) | |
| all_cohorts <- sort(unique(c(aa1$cohorts, aa2$cohorts))) | |
| full_grid <- expand.grid( | |
| year = all_years, | |
| cohorts = all_cohorts, | |
| stringsAsFactors = FALSE | |
| ) | |
| aa_full <- bind_rows(aa1, aa2) %>% | |
| right_join(full_grid, by = c("year", "cohorts")) %>% | |
| arrange(cohorts, year) %>% | |
| mutate(visible = ifelse(n >= 50, TRUE, FALSE)) # keep all rows, flag those with low n | |
| aa_full %>% | |
| ggplot(., aes(x = year, y = mean, color = cohorts, group = cohorts)) + | |
| geom_point(stroke = .25, shape = 21, alpha = .45) + | |
| # geom_line(na.rm = TRUE, linewidth = 1) + | |
| scale_y_continuous(labels = percent) + | |
| scale_color_manual(values = c(met.brewer("Hiroshige", 12))) + | |
| geom_smooth(se = FALSE, method = "loess", span = 0.75) + | |
| facet_wrap(~ cohorts) + | |
| theme_rb() + | |
| theme(axis.text.x = element_text(size = 10)) + | |
| labs(x = "Year", y = "", title = "Share Saying Divorce Should Be Easier to Obtain", | |
| caption = "@ryanburge + @religiondata | Data: General Social Survey, 1974-2022") | |
| save("cohorts_divorce_gss24.png") | |
| aa1 <- gss %>% | |
| filter(year <= 2018) %>% | |
| gss_reltrad6(reltrad) %>% | |
| mutate(divorce = case_when(divlaw == 1 ~ 1, | |
| divlaw == 2 | divlaw == 3 ~ 0)) %>% | |
| group_by(reltrad, year) %>% | |
| mean_ci(divorce, wt = wtssall, ci = .84) | |
| aa2 <- gss %>% | |
| filter(year > 2019) %>% | |
| gss_reltrad6(reltrad) %>% | |
| mutate(divorce = case_when(divlaw == 1 ~ 1, | |
| divlaw == 2 | divlaw == 3 ~ 0)) %>% | |
| group_by(reltrad, year) %>% | |
| mean_ci(divorce, wt = wtssnrps, ci = .84) | |
| both <- bind_rows(aa1, aa2) %>% filter(reltrad != "NA") %>% filter(n > 100) | |
| both %>% | |
| ggplot(., aes(x = year, y = mean, color = reltrad, group = reltrad)) + | |
| scale_y_continuous(labels = percent) + | |
| geom_point(stroke = .25, shape = 21, alpha = .45) + | |
| scale_color_manual(values = c(met.brewer("Austria", 12))) + | |
| geom_smooth(se = FALSE, method = "loess", span = 0.75) + | |
| facet_wrap(~ reltrad) + | |
| theme_rb() + | |
| theme(axis.text.x = element_text(size = 10)) + | |
| labs(x = "Year", y = "", title = "Share Saying Divorce Should Be Easier to Obtain", | |
| caption = "@ryanburge + @religiondata | Data: General Social Survey, 1974-2022") | |
| save("reltrad_divorce_gss24.png") | |
| gg1 <- gss %>% | |
| filter(year < 2020) %>% | |
| mutate( | |
| ever_divorced = case_when( | |
| marital == 3 ~ 1, | |
| marital == 4 ~ 1, | |
| marital %in% c(1, 2) & divorce == 1 ~ 1, | |
| marital %in% c(1, 2) & divorce == 2 ~ 0, | |
| marital == 5 ~ 0, | |
| TRUE ~ NA_real_ | |
| ) | |
| ) %>% | |
| group_by(year) %>% | |
| mean_ci(ever_divorced, wt = wtssall) | |
| gg2 <- gss %>% | |
| filter(year >= 2019) %>% | |
| mutate( | |
| ever_divorced = case_when( | |
| marital == 3 ~ 1, | |
| marital == 4 ~ 1, | |
| marital %in% c(1, 2) & divorce == 1 ~ 1, | |
| marital %in% c(1, 2) & divorce == 2 ~ 0, | |
| marital == 5 ~ 0, | |
| TRUE ~ NA_real_ | |
| ) | |
| ) %>% | |
| group_by(year) %>% | |
| mean_ci(ever_divorced, wt = wtssnrps) | |
| all1 <- bind_rows(gg1, gg2) %>% | |
| mutate(type = "Ever Been Divorced") | |
| gg1 <- gss %>% | |
| filter(year <= 2018) %>% | |
| mutate(divorce = frcode(divlaw == 1 ~ "Easier", | |
| divlaw == 3 ~ "Stay As Is", | |
| divlaw == 2 ~ "More Difficult")) %>% | |
| group_by(year) %>% | |
| ct(divorce, wt = wtssall, show_na = FALSE) | |
| gg2 <- gss %>% | |
| filter(year > 2020) %>% | |
| mutate(divorce = frcode(divlaw == 1 ~ "Easier", | |
| divlaw == 3 ~ "Stay As Is", | |
| divlaw == 2 ~ "More Difficult")) %>% | |
| group_by(year) %>% | |
| ct(divorce, wt = wtssnrps, show_na = FALSE) | |
| all2 <- bind_rows(gg1, gg2) %>% filter(divorce == "Easier") %>% | |
| select(year, mean = pct) %>% mutate(type = "Divorce Should Be Easier") | |
| both <- bind_rows(all1, all2) | |
| both %>% | |
| ggplot(., aes(x = year, y= mean, color = type, group = type)) + | |
| geom_line() + | |
| geom_point(stroke = 1, shape = 21, fill = 'white') + | |
| theme_rb(legend = TRUE) + | |
| scale_color_calc() + | |
| scale_y_continuous(labels = percent, limits = c(0, .60)) + | |
| theme(legend.text = element_text(size = 20)) + | |
| labs(x = "", y= "", title = "Views of Divorce Compared to Divorce Rates", caption = "@ryanburge + @religiondata | Data: General Social Survey, 1974-2022") | |
| save("divorce_rates_div_views.png") | |
| gg1 <- gss %>% | |
| filter(year < 2020, marital != 5) %>% | |
| gss_reltrad6(reltrad) %>% | |
| mutate( | |
| ever_divorced = case_when( | |
| marital == 3 ~ 1, | |
| marital == 4 ~ 1, | |
| marital %in% c(1, 2) & divorce == 1 ~ 1, | |
| marital %in% c(1, 2) & divorce == 2 ~ 0, | |
| marital == 5 ~ 0, | |
| TRUE ~ NA_real_ | |
| ) | |
| ) %>% | |
| group_by(year, reltrad) %>% | |
| mean_ci(ever_divorced, wt = wtssall) | |
| gg2 <- gss %>% | |
| filter(year >= 2019, marital != 5) %>% | |
| gss_reltrad6(reltrad) %>% | |
| mutate( | |
| ever_divorced = case_when( | |
| marital == 3 ~ 1, | |
| marital == 4 ~ 1, | |
| marital %in% c(1, 2) & divorce == 1 ~ 1, | |
| marital %in% c(1, 2) & divorce == 2 ~ 0, | |
| marital == 5 ~ 0, | |
| TRUE ~ NA_real_ | |
| ) | |
| ) %>% | |
| group_by(year, reltrad) %>% | |
| mean_ci(ever_divorced, wt = wtssnrps) | |
| all1 <- bind_rows(gg1, gg2) %>% filter(reltrad != 'NA') | |
| all1 %>% | |
| ggplot(., aes(x = year, y = mean, color = reltrad, group = reltrad)) + | |
| scale_y_continuous(labels = percent) + | |
| geom_point(stroke = .25, shape = 21, alpha = .45) + | |
| scale_color_manual(values = c(met.brewer("Austria", 12))) + | |
| geom_smooth(se = FALSE, method = "loess", span = 0.75) + | |
| facet_wrap(~ reltrad) + | |
| theme_rb() + | |
| theme(axis.text.x = element_text(size = 10)) + | |
| labs(x = "Year", y = "", title = "Share Sharing They Have Been Divorced - Among People Who Have Been Married", | |
| caption = "@ryanburge + @religiondata | Data: General Social Survey, 1974-2022") | |
| save("reltrad_divorced_gss24.png") | |
| gss %>% | |
| filter(year == 2022) %>% | |
| gss_reltrad6(reltrad) %>% | |
| group_by(reltrad) %>% | |
| ct(marital, wt = wtssnrps, show_na = FALSE) %>% filter(marital == 5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment