library(tidyverse)
Warning: package 'tidyverse' was built under R version 4.3.2
Warning: package 'lubridate' was built under R version 4.3.2
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.2     ✔ readr     2.1.4
✔ forcats   1.0.0     ✔ stringr   1.5.0
✔ ggplot2   3.4.2     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.0
✔ purrr     1.0.1     
── 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.3.2
library(wordcloud2)
Warning: package 'wordcloud2' was built under R version 4.3.2
library(babynames)
Warning: package 'babynames' was built under R version 4.3.2

Stats stuff - what libraries I’m using.

babynames |>                             
  filter(year == 2003, sex == "F") |>    
  mutate(rank = row_number()) |>         
  mutate(percent = round(prop * 100, 1)) |> 
  filter(name == "Emma") |> 
  gt()
year sex name n prop rank percent
2003 F Emma 22704 0.0113214 2 1.1

This is how popular my name was the year I was born. It was the second highest baby girl’s name that year.

babynames |>
  filter(year == 2003) |>     # use only one year
  filter(sex == "F") |>       # use only one sex
  slice_max(prop, n=100) |>   # use the top 100 names
  select(name, n) |>          # select the two relevant variables: the name and how often it occurs
  wordcloud2(size = .5, shape = "square", color = "red")                 # generate the word cloud

This is a word cloud of all the most popular girls’ names the year I was born (the larger the word, the more popular the name). Emma is pretty big, meaning it’s pretty popular.

babynames |>                                    # start with the data
  filter(name == "Emma", sex == "F") |>      # choose the name and sex
  mutate(percent = round(prop * 100, 1)) |>     # create a new variable called percent
  ggplot(aes(x = year, y = percent)) +           # put year on the x-axis and prop (proportion) on y
  geom_line(color = "pink")                      # make it a line graph and give the line a color

This is a graph of my name’s popularity over time. It started high, went down, and picked back up again around the start of this century.

babynames |>                                  # Start with the dataset
  filter(name == "Emma", sex == "F") |>    # only look at the name and sex you want
  slice_max(prop, n = 10)
# A tibble: 10 × 5
    year sex   name      n   prop
   <dbl> <chr> <chr> <int>  <dbl>
 1  1881 F     Emma   2034 0.0206
 2  1880 F     Emma   2003 0.0205
 3  1882 F     Emma   2303 0.0199
 4  1883 F     Emma   2367 0.0197
 5  1885 F     Emma   2728 0.0192
 6  1884 F     Emma   2587 0.0188
 7  1886 F     Emma   2764 0.0180
 8  1887 F     Emma   2647 0.0170
 9  1888 F     Emma   3087 0.0163
10  1889 F     Emma   2884 0.0152

This is a table of the years over time that my name has been most popular, arranged by the proportion of how popular it was (right column).

babynames |>
  filter(name == "Emma" | name == "Laura" | name == "Kameron") |> 
  filter(sex == "F") |> 
  ggplot(aes(x = year, y = n, color = name)) +
  geom_line()

This is the popularity of my name over time as compared to Laura and Dr. K’s. I am the red line.

babynames |>
  filter(name == "Andrew" | name == "Tobias" | name == "Thomas") |> 
  filter(sex == "M") |> 
  ggplot(aes(x = year, y = n, color = name)) +
  geom_line()

This is the popularity of the three Spiderman actors’ names over time. As far as I could surmise, the popularity of their movies didn’t change the popularity of their names.