Skip to content

Instantly share code, notes, and snippets.

@arvi1000
Created January 20, 2020 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arvi1000/049bf0704c5fbba645fc19beb654959e to your computer and use it in GitHub Desktop.
Save arvi1000/049bf0704c5fbba645fc19beb654959e to your computer and use it in GitHub Desktop.
library(babynames)
library(tidyverse)
bab <- babynames %>% filter(sex=="F" & year >= 1945)
bab$rgx_match <- as.character(NA)
for(i in c('Amy', 'Beth', 'Meg', 'Jo')) {
rgx <- paste0('^', i, '.*$')
bab$rgx_match <- coalesce(
ifelse(grepl(rgx, bab$name), rgx, NA),
bab$rgx_match)
}
bab %>%
filter(!is.na(rgx_match)) %>%
group_by(year, name=rgx_match) %>%
summarise(n=sum(n)) %>%
ggplot(aes(year, n, color=name, group=name)) +
geom_line() +
geom_vline(xintercept = 1968) +
annotate(geom='text', x=1968, y=20000,
label="1968", angle=90, vjust=-1) +
theme_light() +
labs(title = 'Count of name matches for US female babies',
subtitle = 'Source: SSA',
color='name regex')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment