Skip to content

Instantly share code, notes, and snippets.

@arvi1000
Created May 14, 2019 17:42
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/3b20cadcd1cc7019a29c94d9e4610b27 to your computer and use it in GitHub Desktop.
Save arvi1000/3b20cadcd1cc7019a29c94d9e4610b27 to your computer and use it in GitHub Desktop.
library(babynames)
library(tidyverse)
library(ggrepel)
dat <- babynames %>%
filter(sex=='M') %>%
mutate(chars = nchar(name),
last_char = substr(name, chars, chars)) %>%
group_by(year, last_char) %>%
summarise(prop = sum(prop))
label_dat <-
dat %>%
group_by(last_char) %>%
slice(which.max(prop))
ggplot(dat, aes(x=year, y=prop*100, color=last_char)) +
geom_line() +
geom_point(data=label_dat) +
geom_label_repel(data= filter(label_dat, prop*100 >= 4),
aes(label=toupper(last_char)),
#fill='gray90', color='black',
size=3, segment.size = NA) +
theme_light() +
theme(legend.position='none') +
labs(title = 'Distribution of last letters of US male names',
subtitle = '(points show high water mark for each letter)',
y = 'Percent of babies born that year')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment