Import data

# excel file
data <- read_excel("../00_data/MyData.xlsx")
data
## # A tibble: 10,846 × 8
##    team    team_name  year  total   home   away  week weekly_attendance
##    <chr>   <chr>     <dbl>  <dbl>  <dbl>  <dbl> <dbl> <chr>            
##  1 Arizona Cardinals  2000 893926 387475 506451     1 77434            
##  2 Arizona Cardinals  2000 893926 387475 506451     2 66009            
##  3 Arizona Cardinals  2000 893926 387475 506451     3 NA               
##  4 Arizona Cardinals  2000 893926 387475 506451     4 71801            
##  5 Arizona Cardinals  2000 893926 387475 506451     5 66985            
##  6 Arizona Cardinals  2000 893926 387475 506451     6 44296            
##  7 Arizona Cardinals  2000 893926 387475 506451     7 38293            
##  8 Arizona Cardinals  2000 893926 387475 506451     8 62981            
##  9 Arizona Cardinals  2000 893926 387475 506451     9 35286            
## 10 Arizona Cardinals  2000 893926 387475 506451    10 52244            
## # ℹ 10,836 more rows

State one question

Is there a correlation between the number of fans and the games won? Does the game being home or away affects the number of attendees?

Plot data

# Filter to 2019 and remove NA attendance values
plotdata <- data |>
  filter(year == 2019,
         !is.na(weekly_attendance))

# Plot weekly attendance by week for each team
ggplot(plotdata, aes(x = week, y = weekly_attendance)) +
  geom_line(color = "grey") +
  geom_point(color = "blue") +
  facet_wrap(~team_name) +
  theme_minimal(base_size = 9) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(title = "Weekly Attendance by Team (2019)",
       x = "Week",
       y = "Attendance")

Interpret

This data visualization shows the weeks, and the number of attendees. I need to be able to sort the Y axis in a better way, to be able to read the quantities so I will try to do this and fix this before I continue. I will also want to sort the points based off of home and away, so one color will be home games and one will be away to see of there is a correlation between attendance and the games location.