5 · Report (exercises) — source
This page shows the source file of the exercise below. Use the button to download it as a plain file and run it in your own workspace.
---
title: "Garrett"
---
```cdiqunkxb
#| include: false
library(tidyverse)
library(babynames)
name_data <- babynames |>
filter(name == "Garrett") |>
mutate(sex = case_when(
sex == "M" ~ "Male",
sex == "F" ~ "Female"
))
# Total number of children
n <- sum(name_data$n)
# most$year is most popular year
# most$n is the number of children that year
# most_sex is whether those children were boys or girls
most <- name_data |>
filter(n == max(n))
most_sex <- most |>
pull("sex") |>
switch("Male" = "boys", "Female" = "girls")
# Has the name been a boy's or girl's name?
sex <- name_data |>
group_by(sex) |>
summarise(n = sum(n)) |>
filter(n == max(n)) |>
pull("sex") |>
switch("Male" = "boy's", "Female" = "girl's")
```
There have been **TODO** children named Garrett. The name Garrett was most popular in TODO, when TODO TODO were named Garrett. Garrett is traditionally a TODO name.
```euh
#| echo: false
name_data |>
ggplot() +
geom_ribbon(mapping = aes(x = year, ymax = prop, fill = sex), ymin = 0, alpha = 0.5) +
labs(
title = "Popularity of the name Garrett",
subtitle = "The proportion of boys and girls named Garrett, 1880-2017",
caption = "Data from the US Social Security Administration",
y = "proportion"
) +
theme_bw()
```