Last active
March 1, 2019 19:05
-
-
Save jnaecker/c078d33b20fc0e44edfae5de6a772dae to your computer and use it in GitHub Desktop.
Helping out Casey Wichman
This file contains 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
library(gender) | |
library(genderdata) | |
library(ggplot2) | |
library(dplyr) # so we can pipe with %>% | |
library(purrr) # gives us the map function | |
library(tidyr) # lets us unnest the output from purrr::map | |
graph_sex_ratio <- function(name, years = c(1950:2010)){ | |
tibble(year = years) %>% | |
mutate(gender = map(year, ~gender(name, ., "ssa"))) %>% | |
unnest() %>% | |
ggplot(aes(x = year, y = proportion_male)) + | |
geom_point() + | |
geom_line() + | |
geom_hline(yintercept = 0.5, linetype = "dashed") + | |
labs(x = "Birth year", | |
y = "Proportion male", | |
title = paste("Sex ratio for people named", name, "at birth", sep = " ")) + | |
theme_minimal() | |
} | |
graph_sex_ratio("Casey") | |
graph_sex_ratio("Aubrey") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment