Matthew Beckman & Justin Post June 25, 2021
Here, we join an analysis already in progress…
We’re investigating the popularity of names in the US each year. Matt has chosen to investigate the names of each person in his immediate family: Matthew, Sarah, Eden, Jack, and Hazel. They’re his favorite people, and also his favorite names! He’s feeling torn about how to include his son Jack in the analysis. Jack’s legal name is “Jon” but he is nearly always called “Jack”–the spelling of “Jon” honors Scandinavian heritage on both sides of the family, and the nickname “Jack” specifically honors his great-grandfather.
Some famous persons by each name of the family include:
This document was last modified 2021-06-25 12:31:45.
# libraries
library(tidyverse)
library(dcData)
# data intake
data("BabyNames", package = "dcData")
BabyNamesSupp <-
read_csv("https://jbpost2.github.io/TeachingWithR/datasets/BabyNamesSupp.csv",
col_types = cols(sex = col_character()))
BabyNames2020 <-
read_csv("https://jbpost2.github.io/TeachingWithR/datasets/yob2020.txt",
col_names = FALSE, col_types = cols(X2 = col_character())) %>%
rename(name = X1, sex = X2, count = X3) %>%
mutate(year = 2020)
# Combine data sources
BabyNamesFull <- bind_rows(BabyNames, BabyNamesSupp, BabyNames2020)
According to US Social Security data from 1880 through 2020, “Matthew” was the most frequently occurring name in the family.
# vector of names
beckmans <- c("Matthew", "Sarah", "Eden", "Jack", "Hazel")
BabyNamesFull %>%
filter(name %in% beckmans) %>%
group_by(name) %>%
summarise(total = sum(count, na.rm = TRUE)) %>%
arrange(desc(total))
## `summarise()` ungrouping output (override with `.groups` argument)
We also learned that “Eden” was more balanced between the two sexes when compared to the other names in the family.
BabyNamesFull %>%
filter(name %in% beckmans) %>%
group_by(name, sex) %>% # Task 4.2.3
summarise(total = sum(count, na.rm = TRUE)) %>% # Task 4.2.3
arrange(name)
## `summarise()` regrouping output by 'name' (override with `.groups` argument)
Matt joined Penn State University in 2015, and coincidentally his son Jack was born earlier that year. Interestingly, the name “Jack” was more popular than “Sarah” in 2015, despite the fact that “Sarah” had been far more common when all years had been combined. Perhaps more surprisingly, the name “Hazel” was nearly as common as “Sarah” in that year!
BabyNamesFull %>%
filter(name %in% beckmans, year == 2015) %>%
group_by(name) %>%
summarise(total = sum(count, na.rm = TRUE)) %>%
arrange(desc(total))
## `summarise()` ungrouping output (override with `.groups` argument)
BabyNamesFull %>%
filter(name %in% beckmans, year == 2015) %>%
group_by(name, sex) %>%
summarise(total = sum(count, na.rm = TRUE)) %>%
arrange(name)
## `summarise()` regrouping output by 'name' (override with `.groups` argument)
We want to create a graph that highlights the change in popularity among the names you have chosen over the years.
Task 1: sketch (by hand) the plot you plan to make
Task 2: is your data set aligned to the intended features of this plot?
Task 3: run esquisse::esquisser(GlyphReadyDataSet)
to draft a
plot
esquisser( )
allows you to prototype various plot features,
and then view the corresponding ggplot2
code for your plotesquisser( )
step as you get
moer comfortable with the ggplot2
frameworkTask 4: clean up axis labels, add a title, etc if you have not already done so.
Task 5 (Challenge): add a layer to somehow display overall birth trend for context
Task 6 (Challenge): plot the trend for each name as a relative frequency, rather than raw counts