daily pastebin goal
28%
SHARE
TWEET

Untitled

a guest Jul 12th, 2018 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. rel_ed <- gss %>%
  2.   group_by(year, reltrad) %>%
  3.   mean_ci(educ)  
  4.  
  5.  
  6. all_ed <- gss %>%
  7.   group_by(year) %>%
  8.   mean_ci(educ) %>%
  9.   mutate(reltrad = 8)
  10.  
  11.  
  12. graph <-  bind_rows(rel_ed, all_ed) %>% filter(reltrad != "NA")
  13.  
  14.  
  15. graph <- graph %>%
  16.   mutate(reltrad = recode(reltrad, "3 = 'Black Protestant';
  17.                           4 = 'Catholic';
  18.                           1 = 'Evangelical';
  19.                           2 = 'Mainline';
  20.                           5 = 'Jewish';
  21.                           7 = 'No Faith';
  22.                           6 = 'Other Faith';
  23.                           8 = 'Entire Sample'"))
  24.  
  25.  
  26.  
  27.  
  28. font_add_google("Oswald", "font")
  29.  
  30. showtext_auto()
  31.  
  32.  
  33.  
  34.  
  35. graph %>%
  36.   # filter(reltrad == "Evangelical" | reltrad == "Entire Sample" | reltrad == "Catholic") %>%
  37.   ggplot(., aes(x = year, y = mean, group = reltrad)) +
  38.   geom_line(colour="black") +
  39.   geom_point(shape = 21, colour="black", aes(fill=reltrad), size=5, stroke=1) +
  40.   scale_x_continuous(limits=c(1972,2017)) +
  41.   scale_y_continuous(limits=c(8,18)) +
  42.   theme_minimal() +
  43.   labs(x = "Year", y = "Number of Grades Completed", title = "Education Has Increased for Everyone", caption = "Data: GSS (1977-2016)", fill = "Religious Tradition") +
  44.   theme(text=element_text(size=64, family="font")) +
  45.   scale_fill_lancet()
  46.  
  47. ggsave(file="D://gss_shiny/ed_reltrad.png", type = "cairo-png", width = 15, height =10)
  48.  
  49. g72 <- graph %>%
  50.   filter(year == 1972)
  51.  
  52. g16 <- graph %>%
  53.   filter(year == 2016)
  54.  
  55. new <- bind_cols(g72, g16) %>%
  56.   mutate(newmean = mean1 - mean) %>%
  57.   mutate(diff = newmean - 2.41) %>%
  58.   ungroup(year) %>%
  59.   select(reltrad, diff)
  60.  
  61. graph <- left_join(graph, new)
  62.  
  63.  
  64. font_add_google("Oswald", "font")
  65.  
  66. showtext_auto()
  67.  
  68.  
  69. graph %>%
  70.   # filter(reltrad == "Evangelical" | reltrad == "Entire Sample" | reltrad == "Catholic") %>%
  71.   ggplot(., aes(x = year, y = mean, group = reltrad)) +
  72.   geom_line(colour="black") +
  73.   geom_point(shape = 21, colour="black", aes(fill=reltrad), size=5, stroke=1) +
  74.   scale_x_continuous(limits=c(1972,2017)) +
  75.   scale_y_continuous(limits=c(8,18)) +
  76.   theme_minimal() +
  77.   labs(x = "Year", y = "Number of Grades Completed", title = "Groups that Have Obtained More Education than Average", caption = "Data: GSS (1972-2016)", fill = "Religious Tradition") +
  78.   theme(text=element_text(size=64, family="font")) +
  79.   scale_fill_lancet() +
  80.   gghighlight(diff > 0, label_params = list(size = 20, family = "font"))
  81.  
  82. ggsave(file="D://gss_shiny/ed_reltrad_highlight_above.png", type = "cairo-png", width = 15, height =10)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top