Baby names

library(tidyverse)
── 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.0
✔ 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)
library(wordcloud2)
library(babynames)
filter(babynames, year == 1998)
# A tibble: 27,899 × 5
    year sex   name          n    prop
   <dbl> <chr> <chr>     <int>   <dbl>
 1  1998 F     Emily     26181 0.0135 
 2  1998 F     Hannah    21373 0.0110 
 3  1998 F     Samantha  20193 0.0104 
 4  1998 F     Sarah     19879 0.0103 
 5  1998 F     Ashley    19874 0.0103 
 6  1998 F     Alexis    19778 0.0102 
 7  1998 F     Taylor    18572 0.00958
 8  1998 F     Jessica   18235 0.00941
 9  1998 F     Madison   17786 0.00918
10  1998 F     Elizabeth 15186 0.00784
# ℹ 27,889 more rows
babynames |>
  filter(year == 1998) |> 
  slice_max(prop, n = 5) 
# A tibble: 5 × 5
   year sex   name        n   prop
  <dbl> <chr> <chr>   <int>  <dbl>
1  1998 M     Michael 36614 0.0181
2  1998 M     Jacob   36014 0.0178
3  1998 M     Matthew 31142 0.0154
4  1998 M     Joshua  28088 0.0139
5  1998 F     Emily   26181 0.0135
babynames |>
  filter(year == 1998, sex == "F") |> 
  mutate(percent = round(prop * 100, 1)) |> 
  slice_max(prop, n = 10) |> 
  select(year, sex, name, percent) |> 
  gt() |> 
  tab_header(title = "Most common girl names in 1998")
Most common girl names in 1998
year sex name percent
1998 F Emily 1.4
1998 F Hannah 1.1
1998 F Samantha 1.0
1998 F Sarah 1.0
1998 F Ashley 1.0
1998 F Alexis 1.0
1998 F Taylor 1.0
1998 F Jessica 0.9
1998 F Madison 0.9
1998 F Elizabeth 0.8
babynames |>                             
  filter(year == 1998, sex == "F") |>    
  mutate(rank = row_number()) |>         
  mutate(percent = round(prop * 100, 1)) |> 
  filter(name == "Naomi") |> 
  gt()
year sex name n prop rank percent
1998 F Naomi 1628 0.00084004 190 0.1
babynames |>
  filter(year == 1998) |>     # 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") + WCtheme(1)                 # generate the word cloud

Create a word cloud with a year and sex of your choice, size = .5, red colored words, a square shape, and theme 1. Graphing changes in popularity over time

babynames |>                                    # start with the data
  filter(name == "Naomi", sex == "F") |>      # choose the name and sex
  ggplot(aes(x = year, y = prop)) +              # put year on the x-axis and prop (proportion) on y
  geom_line()                                    # make it a line graph 

babynames |>                                    # start with the data
  filter(name == "Naomi", 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 = "blue")                      # make it a line graph and give the line a color

I was born in 1998. My name was most popular in the years 1917-1925, with a drop off in 1950’s, and re-spiked in 2010. In both these spikes, the name only hit a 0.2 percent in popularity.

babynames |>                                     # Start with the dataset
  filter(name == "Naomi", sex == "F") |>       # only look at the name you want
  slice_max(prop, n = 1)                        # get the year with the top number for that name
# A tibble: 1 × 5
   year sex   name      n    prop
  <dbl> <chr> <chr> <int>   <dbl>
1  2017 F     Naomi  3823 0.00204

Denton was born in 1997 so the uptrend fits.

babynames |>                                  # Start with the dataset
  filter(name == "Denton", sex == "M") |>    # only look at the name and sex you want
  slice_max(prop, n = 10)                         # get the top 10 names
# A tibble: 10 × 5
    year sex   name       n      prop
   <dbl> <chr> <chr>  <int>     <dbl>
 1  1897 M     Denton     9 0.0000738
 2  1881 M     Denton     7 0.0000646
 3  1908 M     Denton    10 0.0000601
 4  1888 M     Denton     6 0.0000462
 5  1942 M     Denton    65 0.0000462
 6  1911 M     Denton    11 0.0000456
 7  1914 M     Denton    31 0.0000454
 8  1913 M     Denton    24 0.0000448
 9  1935 M     Denton    47 0.0000440
10  1994 M     Denton    89 0.0000437

Copy and paste the chunk above and try a few different names and sexes. Could you have guessed when people you know were born? Denton yes, Adelle no, John yes, Sondra yes,

babynames |>
  filter(name == "Sondra") |> 
  ggplot(aes(x = year, y = n)) +
  geom_line()

The name Alice peaked in popularity 55years after the release of the book Alice in Wonderland, had another spike around the 1950’s when the animated Disney version came out, and yet another spike in popularity in 2010 when the live action version was released.

The name Jenny peaked around the 1970’s and 80’s and was slowly becomming less popular even with the release of award winning movie “Forest Gump”.

The name Naomi was most popular around the end of this study and the chart had started trending up in the 70’s making it more and more likely around 1998 that I would be given the name as well.

babynames |>
  filter(name == "Naomi" | name == "Jenny" | name == "Alice") |> 
  filter(sex == "F") |> 
  ggplot(aes(x = year, y = n, color = name)) +
  geom_line()

It looks like the name Diana peaked in the 1950’s just before the time princess Diana was born and has slowly gone down in popularity over time. The name Jennifer was also most popular around the time she was born, however, it wasn’t as popular when and after she became famous for starring on the hit show “Friends”. Hannah, a pseudonym for Miley Cyrus’s show “Hannah Montana” had also peaked in popularity just before the beginning of her show and her becommnig famous.

babynames |>
  filter(name == "Jennifer" | name == "Hannah" | name == "Diana") |> 
  filter(sex == "F") |> 
  filter(year > 1940) |>
  ggplot(aes(x = year, y = n, color = name)) +
  geom_line()