TidyTuesday NHL
# excel file
NHL <- read_csv("../00_data/NHL_attendance.csv")
## Rows: 10846 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): team, team_name
## dbl (6): year, total, home, away, week, weekly_attendance
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
NHL
Who had the best atteadnce this season
NHL %>%
# Select a year
filter(year == 2019) %>%
# Filter for yearly total attendance by team
distinct(team_name, total) %>%
# Plot
ggplot(aes(total, fct_reorder(team_name, total))) +
geom_col(fill = "midnightblue") +
scale_x_continuous(labels = scales::number_format(scale = 0.000001)) +
labs(title = "NFL Teams by Attendance in 2019",
x = "Number of People in Millions", y = NULL)
NHL %>%
# Filter for yearly total attendance by team
distinct(team_name, year, total) %>%
group_by(year) %>%
slice_max(total, n = 5) %>%
ungroup() %>%
ggplot(aes(total, tidytext::reorder_within(team_name, total, year))) +
geom_col(show.legend = FALSE) +
facet_wrap(~year, scales = "free") +
scale_x_continuous(labels = scales::number_format(scale = 0.000001)) +
tidytext::scale_y_reordered() +
labs(title = "Top Five NFL Teams in Attendance",
x = "Number of People in Millions", y = NULL)
The Cowboys are clearly the most popular NFL team of the last decade. What happened to the Redskins?