Babynames: Presidential Names Over Time

Author

Harrison Saini

Hypothesis

For this project I will look at US President names over time to see which ones are the most and least popular over time.

First, I’ll install the necessary packages.

library(babynames)
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.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

Now, we have to load an external data set. The data set was found on Kaggle.

US_Presidents <- read_csv("US-Presidents.csv")
Rows: 46 Columns: 24
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (19): President, Born, start of presidency, end of presidency, Post-pres...
dbl  (5): No., Height (cm), Weight (lbs), Number of kids, Number of marriages

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Next, we must make it so that our data is only displaying the first names of each president.

US_Presidents <- read_csv("US-Presidents.csv")
Rows: 46 Columns: 24
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (19): President, Born, start of presidency, end of presidency, Post-pres...
dbl  (5): No., Height (cm), Weight (lbs), Number of kids, Number of marriages

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
str_split(string = US_Presidents$President, 
          pattern = "[[:space:]]", simplify = TRUE) -> names

as.data.frame(names) -> names

colnames(names)[1] <- 'name'

babynames |> 
  filter(name %in% names$name) |> 
  filter(sex =="M") -> presidential_names

Visualization 1

Now, let’s take a look at how popular each president’s name is over time.

presidential_names |> 
  filter(sex == "M") |> 
  ggplot(aes(year, n, color= name)) + geom_line() +
  theme_classic()+
  labs(x = "president name", 
       y = "number", 
       title = "Presidential names over time")

Using this graph, we can determine that some of the most popular names are John, James,William, George, and Thomas and that a lot of the most popular names peaked around the 50s and 60s. While this graph helps us see which names are the most popular and when theirpopularity peaked, it is hard to pull out the least popular names. Because of this we need to create a better visualization to get a better idea of which names were the least popular and to better compare the names on a proportional basis.

Visualization 2

presidential_names |>
  filter(sex =="M") |> 
  ggplot(aes(reorder(name, prop), prop, fill=name)) + geom_col() + coord_flip()+
  theme_classic()+
  labs(x = "president name", 
       y = "proportion", 
       title = "President name by popularity")

As we can see from the graph, the top 5 presidential names are John, James,William, George, and Thomas

Visualization 3

Next we will take a look at the popularity of the top 5 most popular presidential names over time to determine whether these names follow any trends.

presidential_names|> 
  filter(name %in% c("John", "James","William", "George","Thomas")) |> 
  filter(sex =="M") |> 
  ggplot(aes(year, n, color= name)) + geom_line() + 
  theme_classic() + 
  labs(x = "year", 
       y = "number", 
       title = "The number of the most popular presidential names over time")

As we can see from the graph, all five of the names seemed to have peaked somewhere between 1940 and 1960, with a smaller, more minor peak around the 20s.The only exception to this seems to be the name George, which is not as popular as the rest and saw its peak around 1920.

Visualization 4

Now we will look at the top 5 least popular presidential names to do the same thing. From visualization two, we can find that the top 5 least popular presidential names are Millard, Ulysses, Lyndon, Rutherford, and Barack.

presidential_names|> 
  filter(name %in% c("Millard", "Ulysses", "Lyndon", "Rutherford", "Barack")) |> 
  filter(sex =="M") |> 
  ggplot(aes(year, n, color= name)) + geom_line() + 
  theme_classic() + 
  labs(x = "year", 
       y = "number", 
       title = "The number of the least popular presidential names over time")

For these names, the peaks in popularity happen at different times. The names Barack and Lyndon seemed to have peaked around their respective presidential terms. However, the same cannot be said about the other presidents. The other three names, Rutherford, Millard, and Ulysses seemed to have peaked around 1920. There is a chance that these names peaked earlier during their respective presidential terms, but seeing that the data begins in 1880 and these presidents served before then, that information cannot be discerned.

Conclusion

It can be concluded that, based on this information, that John, James, William, George, and Thomas are the most popular presidential baby names and that the year of each of the respective president’s term likely did not have an influence on parents choosing these names as the majority of these name’s popularity peaked between the 40s and 50s.

It can also be concluded that Millard, Ulysses, Lyndon, Rutherford, and Barack are the least popular baby. However here it is unclear whether the time of the presidential term had an effect on a parents decision to name their children. Three out of the five presidents with the least common names served before the baby name data started to be collected. All three of these names interestingly saw there peak around 1920. The other two names saw major peaks in popularity when the respective president was in office.