Created
May 14, 2019 17:42
-
-
Save arvi1000/3b20cadcd1cc7019a29c94d9e4610b27 to your computer and use it in GitHub Desktop.
This file contains hidden or 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(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