Babynames & Citynames

Author

Berlyn Squillaro

Hypothesis

In this project I will be testing my hypothesis of if there was an increase in Baby names in the US with European cities after WW2 so between the years of 1939-1945 and that if our allies had more prevalent names versus our enemies.

First I will install necessary packages:

library(rvest)
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()
✖ readr::guess_encoding() masks rvest::guess_encoding()
✖ dplyr::lag()            masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(babynames)

The external dataset was loaded here:

wiki <- read_html("https://en.wikipedia.org/wiki/List_of_cities_in_the_European_Union_by_population_within_city_limits")
span <- html_nodes(wiki, "td")

I found the data on Wikipedia.

Step 1

In the code below, I combine the Wikipedia site of European city names and babynames to be in one data set called city_names. Some of the code needs to be fixed a little bit so that is why I created a the filter in city_names for Asia, Africa and Arabia.

wiki_span <- wiki %>%
  html_elements("td:nth-of-type(1) a") %>%
  html_text()

as.data.frame(wiki_span) -> wiki_text
colnames(wiki_text)[1] <- "name"

options(scipen = 100000000)

babynames |> 
  inner_join(wiki_text, relationship = "many-to-many") -> city_names
Joining with `by = join_by(name)`
city_names %>% 
  filter(!name %in% c('Asia', 'Africa','Arabia')) %>% 
  group_by(name) %>% 
  summarize(total = sum(n)) -> city_name_totals

Step 2

In the code below, I combine the Wikipedia site of European city names and babynames to be in one dataset called city_names. Some of the code needs to be fixed a little bit so that is why I created a the filter in city_names for Asia, Africa and Arabia.

city_name_totals %>% 
  arrange(desc(total)) %>% 
  head(15) -> top_15

babynames %>% 
  filter(name %in% top_15$name) %>% 
  ggplot(aes(year, prop, color = name)) + geom_line() 

Step 3

In this first section of code I used the combine data of babynames and city_names to see what top 15 baby names are most prevalent from 1880 ro 2000 and clearly Florence is extremely prevalent so I will remove it.

babynames %>% 
  filter(name %in% top_15$name) %>% 
  filter(!name %in% c('Florence')) %>% 
  ggplot(aes(year, prop, color = name)) + geom_line() +
  facet_wrap(~sex)

Step 4

Now removing Florence I can see that the data is a more comprehensible with out those drastic outliers. Now the most popular names are still female but Paris, Sofia, and Milan. Looking at the code ahead, I am going to take a closer look at the data from 1920 to 1980 and see if there is a huge jump between baby names of European cities.

babynames %>% 
  filter(name %in% top_15$name) %>% 
  filter(year > 1920 & year < 1980 & !name %in% c('Florence')) %>%
  ggplot(aes(year, prop, color = name)) + geom_line()

I found that the data shows there is an increase from 1920 to 1980. When there was the Great Depression there was a decline of baby names because less babies were being produced so this effected the decline in European baby names. In the 1950s there was a huge surge in babies named Valencia and Sofia.

Step 5

Now I am inspired to look closer and see if there was a certain surge in baby names with US allies like Paris, London, and Vienna versus cities like Berlin. Exclusively only looking at the top 15.

babynames |> 
  filter(name %in% c('Paris', 'Sofia', 'Valencia', 'Lyon', 'North')) |> 
  mutate(side = "Allies") -> allies


babynames |> 
  filter(name %in% c('Florence', 'Dresden', 'Berlin', 'Milan', 'Rome', 'Vienna','Bari','Genoa')) |> 
  mutate(side ="Axis") -> axis

allies |> 
  full_join(axis) -> combo
Joining with `by = join_by(year, sex, name, n, prop, side)`

In the code above I combined all the allies Paris, Sofia, Valencia, Lyon and North to one line and then Florence, Dresden, Berlin, Milan, Rome, Vienna, Bari and Genoa. Then I made a join for axis in allied and turned that into the Combo function to help display the two different sets of code on two lines in one graph. This shows that there was about a 5% increase in baby names from 1960 to 2000 in the cities that allied with the US. Where as there was a staggering decrease in baby names of enemies European cities from 1920 to 1980.

Step 6

Now I will use Combo and compare the date based on Gender.

combo |>
  filter(year > 1920 & year < 2000) %>% 
  group_by(side) |> 
  ggplot(aes(year, prop, color = side)) + stat_summary(fun = sum, geom = "line") + facet_wrap(~sex)

combo |>
  filter(year > 1920 & year < 2000) %>% 
  group_by(side) |>
  filter(sex == 'M') %>% 
  ggplot(aes(year, prop, color = side)) + stat_summary(fun = sum, geom = "line") 

Conclusion

This code helped me conclude that overall my hypothesis was correct. Meaning that there was an overall increase in European cities names as baby names in the US from the years after WW2 and that there was an increase in male and female baby names of European cities that allied with the US during WW2. So this helps me conclude that the EU countries that allied with the US then impacted the amount of babies named after European cities in the US.