── 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)
babynames |>filter(year ==2002)
# A tibble: 30,563 × 5
year sex name n prop
<dbl> <chr> <chr> <int> <dbl>
1 2002 F Emily 24463 0.0124
2 2002 F Madison 21773 0.0110
3 2002 F Hannah 18819 0.00953
4 2002 F Emma 16538 0.00838
5 2002 F Alexis 15636 0.00792
6 2002 F Ashley 15342 0.00777
7 2002 F Abigail 15297 0.00775
8 2002 F Sarah 14758 0.00748
9 2002 F Samantha 14662 0.00743
10 2002 F Olivia 14630 0.00741
# ℹ 30,553 more rows
babynames |>filter(year ==2002, sex =="F") |>slice_max(prop, n =5)
# A tibble: 5 × 5
year sex name n prop
<dbl> <chr> <chr> <int> <dbl>
1 2002 F Emily 24463 0.0124
2 2002 F Madison 21773 0.0110
3 2002 F Hannah 18819 0.00953
4 2002 F Emma 16538 0.00838
5 2002 F Alexis 15636 0.00792
This shows that Laila was the 372nd most popular boy name in 2002, with about 800 other babies named Laila for less than 0% of baby girls that year.
babynames |>filter(year ==2002) |># use only one yearfilter(sex =="F") |># 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, shape ="diamond", color ="purple") # generate the word cloud
This shows a wordcloud of the most popular female names from my birth year, 2002.
babynames |># start with the datafilter(name =="Laila", sex =="F") |># choose the name and sexggplot(aes(x = year, y = prop)) +# put year on the x-axis and prop (proportion) on ygeom_line() # make it a line graph
babynames |># start with the datafilter(name =="Laila", sex =="F") |># 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 ="blue") # make it a line graph and give the line a color
Not too sure as to why my graph doesn’t resemble the one before it. However, the above graph (before this one) demonstrates that I was born in 2002, and my name had increased in popularity about three decades before I was born, and then began to drop off in popularity about 10 years later. At its peak year, roughly .001% of baby girls were named Laila.
babynames |># Start with the datasetfilter(name =="Laila", sex =="F") |># only look at the name and sex you wantslice_max(prop, n =10) # get the top 10 names
# A tibble: 10 × 5
year sex name n prop
<dbl> <chr> <chr> <int> <dbl>
1 2009 F Laila 2377 0.00118
2 2012 F Laila 2248 0.00116
3 2008 F Laila 2410 0.00116
4 2010 F Laila 2247 0.00115
5 2011 F Laila 2196 0.00113
6 2007 F Laila 2363 0.00112
7 2013 F Laila 2140 0.00111
8 2014 F Laila 2143 0.00110
9 2016 F Laila 1943 0.00101
10 2015 F Laila 1885 0.000969
The peak “Laila” year was 2009, followed by later years.
babynames |>filter(name =="Carmen"| name =="Laila", sex =="F") |>mutate(percent =round(prop *100, 1)) |>ggplot(aes(x = year, y = percent, color = name)) +geom_line()
The name Carmen (my mother) rose to popularity during the year 1918 and remained consistently common until 1998. It quickly shot back up in popularity during the year 1999 and became far less common roughly 6 years later. The name Laila didn’t rise to popularity until my birth year of 2002, since then, it has remained consistently popular.
babynames |>filter(name =="Marilyn"| name =="Cher"| name =="Rihanna") |>filter(sex =="F") |>ggplot(aes(x = year, y = n, color = name)) +geom_line()
It looks like Marilyn peaked in popularity a few years after Monroe’s birth in 1926 and remained fairly popular throughout her life until the 1950’s. The name Cher became somewhat popular around 1974, roughly 48 years after the singer’s birth. The name Rihanna increased in popularity during the 2000’s and has become less common since the singer’s rise to stardom during that same time.