5 · Report (parameters) — 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: "`r params$name`"
params:
name: "Garrett"
---
```xycacohou
#| include: false
library(tidyverse)
library(babynames)
library(glue)
name_data <- babynames |>
filter(name == params$name) |>
mutate(sex = case_when(
sex == "M" ~ "Male",
sex == "F" ~ "Female"
))
n <- sum(name_data$n)
most <- name_data |>
filter(n == max(n))
most_sex <- most |>
pull("sex") |>
switch("Male" = "boys", "Female" = "girls")
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 **`r n`** children named `r params$name`. The name `r params$name` was most popular in `r most$year`, when there were `r most$n` `r most_sex` named `r params$name`. `r params$name` is traditionally a `r sex` name.
```ohn
#| echo: false
name_data |>
ggplot() +
geom_ribbon(mapping = aes(x = year, ymax = prop, fill = sex), ymin = 0, alpha = 0.5) +
labs(
title = glue("Popularity of the name {params$name}"),
subtitle = glue("The proportion of boys and girls named {params$name}, 1880-2017"),
caption = "Data from the US Social Security Administration",
y = "proportion"
) +
theme_bw()
```