-
Notifications
You must be signed in to change notification settings - Fork 1
/
05-Report-Parameters.qmd
55 lines (47 loc) · 1.26 KB
/
05-Report-Parameters.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
---
title: "`r params$name`"
format:
html:
code-tools:
source: repo
params:
name: "Garrett"
---
```{r setup}
#| 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.
```{r}
#| 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()
```