Skip to content

Instantly share code, notes, and snippets.

@jnaecker
Last active March 1, 2019 19:05
Show Gist options
  • Save jnaecker/c078d33b20fc0e44edfae5de6a772dae to your computer and use it in GitHub Desktop.
Save jnaecker/c078d33b20fc0e44edfae5de6a772dae to your computer and use it in GitHub Desktop.
Helping out Casey Wichman
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