I’ll first load in all the libraries I need for this assignment, just in case.
library(tidyverse)
Warning: package 'tidyverse' was built under R version 4.2.3
Warning: package 'ggplot2' was built under R version 4.2.3
Warning: package 'tibble' was built under R version 4.2.3
Warning: package 'tidyr' was built under R version 4.2.3
Warning: package 'readr' was built under R version 4.2.3
Warning: package 'purrr' was built under R version 4.2.3
Warning: package 'dplyr' was built under R version 4.2.3
Warning: package 'stringr' was built under R version 4.2.3
Warning: package 'forcats' was built under R version 4.2.3
Warning: package 'lubridate' was built under R version 4.2.3
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.4.4 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.1
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(gt)
Warning: package 'gt' was built under R version 4.2.3
library(wordcloud2)
Warning: package 'wordcloud2' was built under R version 4.2.3
library(babynames)
Warning: package 'babynames' was built under R version 4.2.3
Since my name is in Vietnamese, and I did check that no one in the data set was born with the name “Du” at any point in time, I will not be using my real name. Instead, I will use the name “Chad” as it is what I usually go by online.
Here is how popular the name “Chad” was the year I was born - 2004:
babynames |>filter (year ==2004, sex =="M") |>#filter sex and yearmutate (rank =row_number()) |>#make rank variablemutate (percent =round(prop *100, 2)) |>#make percent from propfilter (name =="Chad") |>#find specific nameselect (year,sex,name,n,percent,rank) |>#select variables to displaygt() |>tab_header(title ="Name Rank of Chad") #set name
Name Rank of Chad
year
sex
name
n
percent
rank
2004
M
Chad
828
0.04
343
Looks like the name wasn’t very popular, only at rank 343. Here is a word cloud of the most popular male names during 2004 in the US:
babynames |>filter(year ==2004) |># use only one yearfilter(sex =="M") |># use only one sexslice_max(prop, n=100) |># use the top 100 namesselect(name, n) |># select the two relevant variables: the name and how often it occurswordcloud2(size = .5) +WCtheme(2) # generate the word cloud
Looks like Jacob was the most popular male baby name in 2004. Here is a graph of the popularity of the name “Chad,” as well as the specific years it was most popular:
babynames |># start with the datafilter(name =="Chad", sex =="M") |># choose the name and sexmutate(percent =round(prop *100, 1)) |># create a new variable called percentggplot(aes(x = year, y = percent)) +# put year on the x-axis and prop (proportion) on ygeom_line(color ="green") # make it a line graph and give the line a color
babynames |># Start with the datasetfilter(name =="Chad", sex =="M") |># only look at the name and sex you wantslice_max(prop, n =10) |># get the top 10 namesgt() |>tab_header(title ="Chad Name Most Popular Years")
Chad Name Most Popular Years
year
sex
name
n
prop
1972
M
Chad
13400
0.00800155
1973
M
Chad
12884
0.00798161
1975
M
Chad
12844
0.00791360
1974
M
Chad
12799
0.00784858
1976
M
Chad
11776
0.00721027
1971
M
Chad
12133
0.00667242
1977
M
Chad
10835
0.00633678
1978
M
Chad
10113
0.00591715
1979
M
Chad
10159
0.00566964
1980
M
Chad
10150
0.00547163
It seems like the name “Chad” rocketed in popularity in the early 1970s and tapered off after that. I’m going to compare the name’s popularity to that of my friends’, “Gage” and “Brock”:
babynames |>filter(name =="Chad"| name =="Gage"| name =="Brock") |>filter(sex =="M") |>filter(year >1950) |>ggplot(aes(x = year, y = n, color = name)) +geom_line()
I suppose “Gage” and “Brock” aren’t very popular names. How about we take some inspiration from some of my favorite childhood cartoons? Let’s use the name “Finn” from the show “Adventure Time” released in 2010 and “Phineas” from “Phineas & Ferb” in 2007:
babynames |>filter(name =="Finn"| name =="Phineas") |>filter(sex =="M") |>filter(year >1980) |>ggplot(aes(x = year, y = n, color = name)) +geom_line()
Looks like the name “Finn” wasn’t too popular until the 21st century, where it started climbing upwards. Since the show was released in 2010, I’m not sure how much of an effect it had on this increase. “Phineas,” on the other hand, had its peak in 2010, 3 years after the shows release. Because the name was hardly used before then, I think the show could have made the name more popular.