Last active
June 23, 2023 20:32
-
-
Save chelseaparlett/a836c72b92dafac08b3b9d7d48ab1a6f to your computer and use it in GitHub Desktop.
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
#libs | |
library(tidyverse) | |
#---CHELSEA--- | |
# load in data | |
california <- read.csv("./Data/namesbystate/STATE.CA.TXT", header = FALSE) | |
colnames(california) <- c("State", "Gender", "Year", "Name", "Count") | |
# filter data | |
california_sub <- california %>% filter(Name == "Chelsea", Gender == "F") | |
# plot | |
p <- ggplot(california_sub, aes(x = Year, y = Count)) + | |
geom_line(size = 1) + | |
geom_point(size = 2) + | |
geom_point(data = subset(california_sub, Year == 1993), | |
color = "blue", | |
size = 10, | |
alpha = 0.75) + | |
labs(title = "Popularity of the Name Chelsea in California", | |
y = "Number of Chelseas Born") + | |
geom_label(data = subset(california_sub, Year == 1993), | |
label = "Chelsea Born", | |
hjust = -0.2, vjust = 0.5, | |
fill = "blue", | |
colour = "white", | |
alpha= 0.75, | |
size = 5, | |
label.padding = unit(0.5, "lines")) + | |
theme_minimal() + | |
theme(panel.grid.minor = element_blank(), | |
panel.grid.major = element_blank()) | |
#---FLORENCE--- | |
# funcs | |
read_nat <- function(fn){ | |
year <- substr(fn,17,20) | |
doc <- read.csv(fn, header = FALSE) | |
colnames(doc) <- c("Name", "Gender", "Count") | |
doc["Year"] <- as.numeric(year) | |
doc | |
} | |
# load in data | |
filenames <- paste0("./Data/names/yob", 1880:2022, ".txt") | |
national <- lapply(filenames, read_nat) | |
national <- do.call(rbind, national) | |
# filter data | |
national_sub <- national %>% filter(Name == "Florence", Gender == "F") | |
# plot | |
p <- ggplot(national_sub, aes(x = Year, y = Count)) + | |
annotate(geom = "rect", xmin = 1880, xmax = 1910, | |
ymin = 0, ymax = max(national_sub["Count"]), | |
alpha = 0.2, | |
fill = "blue") + | |
geom_line() + | |
geom_point() + | |
labs(title = "Popularity of the Name Florence", | |
y = "Number of Florences Born") + | |
annotate(geom = "text", | |
label = "Florence\nNightingale\nAlive", | |
x = 1895, y = max(national_sub["Count"])-1000, color = "blue", | |
fill = "blue") + | |
theme_minimal() + | |
theme(panel.grid.minor = element_blank(), | |
panel.grid.major = element_blank()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment