# load packages
library(tidyverse)
library(plotly)Eli Germain Madden Data Analysis
# load data
madden_data <- read_csv(file = "C:/Users/elige/Downloads/madden-23.csv")
# preview data
head(madden_data)# A tibble: 6 × 80
`Full Name` Team Position college awareness_rating throwPower_rating
<chr> <chr> <chr> <chr> <dbl> <dbl>
1 Aaron Donald Rams RE Pittsburgh 99 20
2 Davante Adams Raiders WR Fresno Sta… 99 45
3 Myles Garrett Browns RE Texas AM 98 55
4 Trent Williams 49ers LT Oklahoma 99 12
5 Cooper Kupp Rams WR Eastern Wa… 99 59
6 Jalen Ramsey Rams CB Florida St… 98 27
# ℹ 74 more variables: kickReturn_rating <dbl>, leadBlock_rating <dbl>,
# strength_rating <dbl>, bCVision_rating <dbl>, catchInTraffic_rating <dbl>,
# playAction_rating <dbl>, pursuit_rating <dbl>, plyrAssetname <chr>,
# mediumRouteRunning_rating <dbl>, catching_rating <dbl>,
# acceleration_rating <dbl>, spinMove_rating <dbl>, height <dbl>,
# finesseMoves_rating <dbl>, spectacularCatch_rating <dbl>,
# runBlock_rating <dbl>, tackle_rating <dbl>, injury_rating <dbl>, …
Scatterplot Of Players
scatterplot <- plot_ly(data = madden_data, x = ~overall_rating, y = ~totalSalary,
type = "scatter", mode = "markers",
marker = list(size = 4, opacity = 0.6, color = "lightblue"))
hover_text <- paste("Player: ", madden_data$`Full Name`,
"<br>Position: ", madden_data$Position,
"<br>Total Salary: $", madden_data$totalSalary,
"<br>Overall Rating: ", madden_data$overall_rating)
scatterplot <- scatterplot %>% add_trace(text = hover_text, hoverinfo = "text", showlegend = FALSE)
scatterplot <- scatterplot %>% layout(
title = "Relationship between Overall Rating and Total Salary of NFL Players",
xaxis = list(title = "Overall Rating"),
yaxis = list(title = "Total Salary")
)
scatterplotDumbell chart of Player Pay by Position
position_summary <- madden_data %>%
group_by(Position) %>%
summarize(
Avg_TotalSalary = mean(totalSalary),
Avg_SigningBonus = mean(signingBonus),
Players_Count = n()
) %>%
arrange(Avg_TotalSalary)
traces <- list()
for (i in 1:nrow(position_summary)) {
row_data <- position_summary[i, ]
trace <- plot_ly(
x = c(row_data$Avg_TotalSalary, row_data$Avg_SigningBonus),
y = c(row_data$Position, row_data$Position),
mode = 'markers+lines',
type = 'scatter',
line = list(color = 'lightgreen', width = 1),
marker = list(color = c('lightgreen', 'darkgreen'), size = 6, symbol = 'circle'),
showlegend = FALSE,
hoverinfo = 'text',
text = paste(
"Position: ", row_data$Position, "<br>",
"Avg Total Salary: $", scales::comma(row_data$Avg_TotalSalary), "<br>",
"Avg Signing Bonus: $", scales::comma(row_data$Avg_SigningBonus), "<br>",
"Players Count: ", row_data$Players_Count
)
)
traces[[i]] <- trace
}
dumbbell_plot <- subplot(traces, nrows = length(traces), shareX = TRUE) %>%
layout(
title = "Average Signing Bonus and Total Salary by Position",
xaxis = list(title = "Average Salary and Signing Bonus"),
yaxis = list(title = "Position"),
showlegend = FALSE
)
dumbbell_plotFurther Data Visualizations
# Plot 1 - Top Teams by Average Player Rating
average_rating_by_team <- madden_data %>%
group_by(Team) %>%
summarise(Avg_Rating = mean(overall_rating, na.rm = TRUE)) %>%
arrange(desc(Avg_Rating)) # Arranging teams by average rating
average_rating_chart <- plot_ly(data = average_rating_by_team, x = ~Team, y = ~Avg_Rating,
type = "bar",
text = ~paste("Team: ", Team, "<br>",
"Average Rating: ", round(Avg_Rating, 2)),
hoverinfo = "text"
)
average_rating_chart <- average_rating_chart %>% layout(
title = "Average Overall Rating by Team",
xaxis = list(title = "Team"),
yaxis = list(title = "Average Overall Rating"),
showlegend = FALSE
)
average_rating_chart# Plot 2 - Overall Player Rating For Top 4 Teams
top_4 <- c("Ravens", "Bills", "49ers", "Patriots")
top_4_data <- madden_data %>%
filter(Team %in% top_4)
box_plot <- top_4_data %>%
plot_ly(x = ~Team, y = ~overall_rating,
type = "box", color = ~Team, colors = "Set1",
text = ~paste("Team: ", Team, "<br>",
"Q1: ", quantile(overall_rating, 0.25), "<br>",
"Median: ", median(overall_rating), "<br>",
"Q3: ", quantile(overall_rating, 0.75), "<br>",
"Min: ", min(overall_rating), "<br>",
"Max: ", max(overall_rating)),
hoverinfo = 'text') %>%
layout(
title = "Distribution of Player Overall Ratings in Top 4 Teams",
xaxis = list(title = "Team"),
yaxis = list(title = "Overall Rating")
)
outliers <- top_4_data %>%
group_by(Team) %>%
summarize(outlier = list(boxplot.stats(overall_rating)$out))
for (i in seq_along(outliers$outlier)) {
for (j in seq_along(outliers$outlier[[i]])) {
player <- filter(top_4_data, Team == outliers$Team[i], overall_rating == outliers$outlier[[i]][j]) %>%
select(`Full Name`, overall_rating) %>%
slice(1)
box_plot <- add_annotations(box_plot, text = paste(player$`Full Name`, player$overall_rating),
x = outliers$Team[i], y = outliers$outlier[[i]][j],
xref = "x", yref = "y", showarrow = FALSE,
xshift = 45, font = list(size = 8))
}
}
box_plotTwo additional plots were created for the analysis of the Madden stats dataset. The first plot, a bar chart of average overall rating by team, was used to determine the top teams by average overall rating. Based on this first step, the top 4 teams were determined to be thew Bills, Pats, 49ers and Ravens. These teams were then mapped against one another using a comparative boxplot. using the boxplot, one can easily see that although all 4 teams have a similar overall rating, some have larger spreads than ohers. Of the teams, the 49ers seem to benefit the most from upper outliers, with three players listed with ratings of 94 and above.The Patriots on the other hand, seem the most consistent of the four, with a relatively small range and seemingly central distribution. The Ravens have the largest spread, excluding outliers of the four teams plotted.