This notebook combines standard data sets containing information on professional football club and football player data from the top five football leagues in Europe. It explores and compares the data in attempt to find useful information. The data can be used for educational purposes and hypothetically to give insights to improve sports betting players’ odds when creating/ placing bets. All data was extracted from FBREF.com (2022, December).
#Get working directory
getwd()
## [1] "D:/R Studio/R Projects/DataVisualisationAssignment2"
#Assign data sets
premierLeagueStandardData <- read.csv("PremierLeague.csv", encoding = "UTF-8")
laLigaStandardData <- read.csv("LaLiga.csv", encoding = "UTF-8")
bundesligaStandardData <- read.csv("Bundesliga.csv", encoding = "UTF-8")
seriaAStandardData <- read.csv("SerieA.csv", encoding = "UTF-8")
ligue1StandardData <- read.csv("Ligue1.csv", encoding = "UTF-8")
Add ‘League’ Features to each data set
#Create vector that holds the different possible values for the new feature
leagueName <- c("Premier League", "La Liga","Bundesliga","Serie A","Ligue 1")
#Create function which adds feature
CreateFeature <- function(dataset,values, featureName)
{
for(i in dataset)
{
dataset[paste(featureName)] <- values
}
return(dataset)
}
#Call function on each data set
for(i in 1:length(leagueName))
{
premierLeagueStandardData <- CreateFeature(premierLeagueStandardData,leagueName[1], featureName = "League")
laLigaStandardData <- CreateFeature(laLigaStandardData,leagueName[2], featureName = "League")
bundesligaStandardData <- CreateFeature(bundesligaStandardData,leagueName[3], featureName = "League")
seriaAStandardData <- CreateFeature(seriaAStandardData,leagueName[4], featureName = "League")
ligue1StandardData <- CreateFeature(ligue1StandardData,leagueName[5], featureName = "League")
}
Create list that contains each data frame
#Create list containing each data frame
dataSetList <- list(premierLeagueStandardData,laLigaStandardData,bundesligaStandardData,seriaAStandardData,ligue1StandardData)
Create function which merges data frames
#Create function for merging datasets
MergeDataFrames <- function(df1,df2)
{
merge(df1,df2,all.x = T, all.y = T)
}
#Combine elements of "dataSetList" in "MergeDataFrames" function using "Reduce()"
finalDataFrame <- Reduce(MergeDataFrames,dataSetList)
Rename columns
#Create vector that will replace non communicative labels with concise labels
conciseLabels <- c("Rank","Player","Nation","Position","Club","Age","Born","Matches Played","Starts","Minutes Played","90s Played","Total Goals","Total Assists","Non-Penalty Goals","Penalty Kicks Made","Penalty Kicks Attempted","Yellow Cards","Red Cards","Goals per 90","Assists per 90","Goals plus Assists per 90","Goals minus Penalty Kicks Made per 90","Goals plus Assists minus Penalty Kicks made per 90","Expected Goals per Season","Non-penalty Excpected Goals","Expected Assists per Season","Non-penalty Expected Goals plus Expected Assists per Season","Expected Goals per 90","Expected Assists per 90","Epected Goals + Assists per 90","Non-penalty Expected Goals per 90","Non-penalty Expected Goals + Expected Assists per 90","Matches", "XName", "League")
#Change column names
colnames(finalDataFrame) <- conciseLabels
Remove empty and unneeded rows
#Remove unwanted rows
finalDataFrame <- finalDataFrame[finalDataFrame != '',]
Remove rows with NA values, these values were created when running the previous block, they need to be removed, original data sets had no NA values
#Remove empty rows
finalDataFrame <- finalDataFrame[!apply(finalDataFrame == "", 1, all),]
#install.packages("dplyr")
#Use "dplyr" library
library(dplyr)
#Convert blank values to NA
finalDataFrame <- finalDataFrame %>% mutate_all(na_if,"")
#Remove NA values
finalDataFrame <- na.omit(finalDataFrame)
#Remove last rows (contains feature names only)
finalDataFrame <- finalDataFrame[nrow(finalDataFrame) - 5:nrow(finalDataFrame),]
Confirm no NA values remain
#Value outputs zero rows meaning there are no NA values present
finalDataFrame[rowSums(is.na(finalDataFrame)) > 0,]
Clean columns
#Remove lower case letters in nation names for clarity
finalDataFrame[,"Nation"] <- substring(finalDataFrame[,"Nation"],4)
#Remove space at beginning for England (only abbreviation with three characters, others had two)
finalDataFrame$Nation[finalDataFrame$Nation == " ENG"] <- "ENG"
Filter features
#Remove features that will be of no use to our user story, create vector that holds the feature names
featuresToRemove <- c("Born","Matches","Rank", "XName")
#Remove features
finalDataFrame <- finalDataFrame[ ,!(names(finalDataFrame) %in% featuresToRemove)]
Row numbers start with 2, change them to start with 1 for clarity
#Index row numbers by 1
rownames(finalDataFrame) <- 1:nrow(finalDataFrame)
Convert character data that is represented by strings to factors, calculations can be performed on this data later if needed
#Create vector of indices to have their type changed
numericIndices <- c(5:8,10:16)
doublesIndices <- c(9,17:30)
#Start at six as we want first six columns to be of type character
for(i in 5: nrow(finalDataFrame))
{
if(i %in% numericIndices)
{
#Replace commas with empty to avoid NA coercion
finalDataFrame[[i]] <- as.numeric(gsub(",","",finalDataFrame[[i]]))
}
if(i %in% doublesIndices)
{
#Replace commas with empty to avoid NA coercion
finalDataFrame[[i]] <- as.double(gsub(",","",finalDataFrame[[i]]))
}
}
Create new datasets which contain features for countries, clubs and leagues which could be of use for later
#Use sql to simplify process
#Install.packages("sqldf")
library(sqldf)
#Create team stats feature to be merged with final data frame later
team_stats <- sqldf("select Club, sum(`Total Goals`) as `Club Goals`,sum(`Total Assists`) as `Club Assists`, sum(`Yellow cards`) as `Club Yellows`, sum (`Red cards`) as `Club Reds` from finalDataFrame group by club")
#Create country stats
nation_stats <- sqldf("select Nation, sum(`Total goals`) as `Country Goals`,sum(`Total Assists`) as `Country Assists`, sum(`Yellow cards`) as `Country Yellows`, sum (`Red cards`) as `Country Reds` from finalDataFrame group by Nation")
#Create league stats
league_stats <- sqldf("select League, sum(`Total goals`) as `League Goals`,sum(`Total Assists`) as `League Assists`, sum(`Yellow cards`) as `League Yellows`, sum (`Red cards`) as `League Reds` from finalDataFrame group by League")
Create list that contains new datasets, then merge with the final data set
#Create list containing each data frame
newFeatureDataSets <- list(team_stats,nation_stats,league_stats)
Reuse function from earlier to merge datasets
#Combine elements of "dataSetList" in "MergeDataFrames" function using "Reduce()"
finalDataFrame <- Reduce(MergeDataFrames,newFeatureDataSets,finalDataFrame)
Add features to finalDataFrame
#Create new feature to arrange instances by goals and assists
finalDataFrame$GoalsAndAssists <- finalDataFrame$`Total Goals` + finalDataFrame$`Total Assists`
#Create new variable to measure club aggression
finalDataFrame$clubAggression <- finalDataFrame$`Club Reds` + finalDataFrame$`Club Yellows`
Load in libraries for that may be of use for visualization
#install.packages("ggplot2")
library(ggplot2)
#install.packages("ggpubr")
library(ggpubr)
#install.packages("ggthemes")
library(ggthemes)
#install.packages("png")
library(png)
#install.packages("jpeg")
library(jpeg)
#install.packages("plotly")
library(plotly)
#install.packages("lubridate")
library(lubridate)
#install.packages("stringr")
library(stringr)
#install.packages("extrafont")
library(extrafont)
#install.packages("readr")
library(readr)
#install.packages("scales")
library(scales)
#install.packages("reshape2")
library(reshape2)
Create Static Graph, here expected goals per season is compared against minutes played. The point of this was to see if there is a correlation between minutes played and expected goals per season.
#Create scatter plot that graphs expected goals against total minutes played, this gives a visual representation of the correlation
iteration1 = finalDataFrame %>% arrange(desc(`Expected Goals per Season`)) %>% top_n(200, `Expected Goals per Season`) %>%
ggplot(aes(x = `Expected Goals per Season`, y = `Minutes Played`, color = League, size = `Total Goals`, text = paste0('Player : ', Player))) +
geom_point(alpha = 0.7, stroke = 0) +
theme_fivethirtyeight() +
scale_size(range = c(1,8), guide = "none") +
scale_x_log10() +
labs(title = "Expected Goals vs Minutes Played per Season (Top 200 Players)", x = "Expected goals per season", y = "Total minutes played", caption = "Source: FBREF.com") +
theme(axis.title = element_text(),text = element_text(family="DM Sans"), legend.text = element_text(size=10)) + scale_color_brewer(palette = "Set2")
Create filterable version of graph using ggplotly
#Configure display settings
font = list(
family = "Arial",
size = 15,
color = "Black"
)
label = list(
bordercolor = "white",
font = font
)
#Convert graph to interactive graph using plotly
ggplotly(iteration1)%>%layout(xaxis = list(fixedrange = TRUE), yaxis = list(fixedrange =TRUE)) %>% config(displayModeBar = FALSE) %>% style(hoverlabel = label) %>% layout(font = font)
## Warning: plotly.js does not (yet) support horizontal legend items
## You can track progress here:
## https://github.com/plotly/plotly.js/issues/53
Create table that contains the amount of information we want to display
#Allocate table length
len <- 5
#Create table of length len, this table is used later on upon improving this iteration
topGoalsAssists <- finalDataFrame %>% arrange(desc(`Total Goals`)) %>% top_n(len, `Total Goals`)
Display information in stacked bar chart
#Create table containing only necessary information for graph
goalAssistsTab <- sqldf ( "select Player, `Total Goals` as Goals,
`Total Assists` as Assists from topGoalsAssists group by Player")
#Use previous table to create table appropriate for making grouped bar chart, this is done using the reshape2 package
goalAssistsMelt<-melt(goalAssistsTab,id.vars = c('Player'))
#Create graph
iteration2 <- ggplot(goalAssistsMelt, aes(x = reorder(Player,value) , y = value, fill = variable,text = paste0("Type : ", variable, "</br></br>", "Player : ",Player,"</br>",variable," : ", value ))) +
geom_bar(stat="identity", position = 'dodge') +
theme_fivethirtyeight() +
scale_size(range = c(1,8), guide = "none") +
xlab("hihih") +
labs(title = "Top goal contributing players in Premier League, Bundesliga, Ligue q, Serie A, and La Liga combined - (Top 5)",size = 5, x = "Player", y = "Count", caption = "Source: FBREF.com") +
theme(plot.title = element_text(size = 11),text = element_text(family="DM Sans"), legend.text = element_text(size=10)) +
scale_fill_discrete(name = "Contribution type",labels = c("Goals","Assists"))
Display using plotly
#Configure display settings
font = list(
family = "Arial",
size = 16,
color = "Black"
)
label = list(
bordercolor = "white",
font = font
)
#Transform graph into interactive graph using plotly package
ggplotly(iteration2,tooltip = c('text')) %>%layout(xaxis = list(fixedrange = TRUE), yaxis = list(fixedrange =TRUE)) %>% config(displayModeBar = FALSE) %>% style(hoverlabel = label) %>% layout(font = font)
## Warning: plotly.js does not (yet) support horizontal legend items
## You can track progress here:
## https://github.com/plotly/plotly.js/issues/53
Create table that contains the amount of information we want to display
#Determine length of table
len <- 5
#Create table for displaying player aggression statistics, this table is used later on when trying to improve this iteration
topAggressive <- sqldf("select clubAggression, `Club Yellows`, `Club Reds`, club from finalDataFrame Group by Club ") %>% arrange(desc(clubAggression)) %>% top_n(len, clubAggression)
Display information in stacked bar chart
#Create new table containing the specific information we want to show
aggressionTab <- sqldf ( "select Club, sum(`Club Reds`) as Reds,
sum(`Club Yellows`) as Yellows from topAggressive group by Club")
#Use previous table to create table appropriate for stacked bar charts
aggTabMelt<-melt(aggressionTab,id.vars = c('Club'))
#Create stacked bar chart using ggplot
iteration3 <- ggplot(aggTabMelt, aes(x = reorder(Club,value) , y = value, fill = variable,text = paste0("Club : ",Club,"</br></br>",variable, " : ", value))) +
geom_bar(stat="identity", position = 'stack') +
theme_fivethirtyeight() +
scale_size(range = c(1,8), guide = "none") +
xlab("hihih") +
labs(title = "Most aggressive clubs in Premier League, Bundesliga, Ligue q, Serie A, and La Liga combined - (Top 5)",size = 5, x = "Club", y = "Count", caption = "Source: FBREF.com") +
theme(plot.title = element_text(size = 12),text = element_text(family="DM Sans"), legend.text = element_text(size=10)) +
scale_fill_discrete(name = "Card Type",labels = c("Red","Yellow"))
Display using plotly
#Configure display settings
font = list(
family = "Arial",
size = 18,
color = "Black"
)
label = list(
bordercolor = "white",
font = font
)
#Display graph using plotly, this displays hover information
ggplotly(iteration3,tooltip = c('text')) %>%layout(xaxis = list(fixedrange = TRUE), yaxis = list(fixedrange =TRUE)) %>% config(displayModeBar = FALSE) %>% style(hoverlabel = label) %>% layout(font = font)
## Warning: plotly.js does not (yet) support horizontal legend items
## You can track progress here:
## https://github.com/plotly/plotly.js/issues/53
Create expected goals per season accuracy feature
#Create feature that represents the difference between goals and expected goals
finalDataFrame$diff <- abs((finalDataFrame$`Expected Goals per Season`) - (finalDataFrame$`Total Goals`))
#Rename columns
colnames(finalDataFrame)[colnames(finalDataFrame) == "diff"] = "Goals/ Exp Goals Difference"
#Create scatter plot using ggplot2, here the strength of the correlation between both variables can be visualized, as well as allowing us to observe the accuracy of the expected goals statistic
graph1 <- finalDataFrame %>% arrange(desc(`Expected Goals per Season`)) %>% top_n(250, `Expected Goals per Season`) %>%
ggplot(aes(x = `Expected Goals per Season`, y = `Total Goals`, color = `Goals/ Exp Goals Difference`, size = `Total Goals`, text = paste0('Player : ', Player,"</br>", "Club : ", Club))) +
geom_point(alpha = 0.85, stroke = 0) +
theme_fivethirtyeight() +
scale_size(range = c(1,8), guide = "none") +
scale_x_log10() +
labs(title = "Expected Goals vs Total Goals per Season (Top 250 Players)", x = "Expected goals per season", y = "Total Goals per Season", caption = "Source: FBREF.com") +
theme(axis.title = element_text(),text = element_text(family="DM Sans"), legend.title = element_text(size = 11)) +
labs(color=' Goals/ expected goals difference')
Create interactive version of graph using plotly
#Configure display settings
font = list(
family = "Arial",
size = 15,
color = "White"
)
label = list(
bordercolor = "white",
font = font
)
#Congfigure plotly settings
graph1 <- ggplotly(graph1, tooltip = c("x","y","text","color"))%>%layout(xaxis = list(fixedrange = TRUE), yaxis = list(fixedrange =TRUE)) %>% style(hoverlabel = label) %>% layout(font = font) %>% config(displayModeBar = FALSE)
## Warning: plotly.js does not (yet) support horizontal legend items
## You can track progress here:
## https://github.com/plotly/plotly.js/issues/53
#Display Graph
graph1
Prepare trables for interactive graph
#Assign table length
len <- 5
#Create tables for each dropdown option
defenders <- sqldf("select * from finalDataFrame where Position = 'DF'") %>% arrange(desc(GoalsAndAssists)) %>% top_n(len, GoalsAndAssists)
midfielders <- sqldf("select * from finalDataFrame where Position = 'MF'") %>% arrange(desc(GoalsAndAssists)) %>% top_n(len, GoalsAndAssists)
forwards <- sqldf("select * from finalDataFrame where Position = 'FW'") %>% arrange(desc(GoalsAndAssists)) %>% top_n(len, GoalsAndAssists)
attackingMidfielders<- sqldf("select * from finalDataFrame where Position = 'MFFW' OR Position = 'FWMF'") %>% arrange(desc(GoalsAndAssists)) %>% top_n(len, GoalsAndAssists)
attackingDefenders <- sqldf("select * from finalDataFrame where Position = 'DFFW' OR Position = 'FWDF'") %>% arrange(desc(GoalsAndAssists)) %>% top_n(len, GoalsAndAssists)
Display graph
font = list(
family = "Arial",
size = 20,
color = "Black"
)
label = list(
bordercolor = "Black",
font = font
)
graph2 <- plot_ly() %>%
add_trace( x = NULL, y =NULL, visible = F) %>%
add_trace( x = topGoalsAssists$Player, y = topGoalsAssists$`Total Goals`, visible = T,type = 'bar',name = "Goals",textposition = 'auto', marker = list(color = 'rgb(58,200,225)', line = list(color = 'rgb(8,48,107)', width = 1.5))) %>%
add_trace( x = topGoalsAssists$Player, y = topGoalsAssists$`Total Assists`, visible = T,type = 'bar',name = "Assists",textposition = 'auto', marker = list(color = 'rgb(58,90,225)', line = list(color = 'rgb(8,48,107)', width = 1.5))) %>%
add_trace( x = defenders$Player, y = defenders$`Total Goals`, visible = F,type = 'bar',name = "Goals",textposition = 'auto', marker = list(color = 'rgb(58,200,225)', line = list(color = 'rgb(8,48,107)', width = 1.5))) %>%
add_trace( x = defenders$Player, y = defenders$`Total Assists`, visible = F,type = 'bar',name = "Assists",textposition = 'auto', marker = list(color = 'rgb(58,90,225)', line = list(color = 'rgb(8,48,107)', width = 1.5))) %>%
add_trace( x = midfielders$Player, y = midfielders$`Total Goals`, visible = F,type = 'bar',name = "Goals",textposition = 'auto', marker = list(color = 'rgb(58,200,225)', line = list(color = 'rgb(8,48,107)', width = 1.5))) %>%
add_trace( x = midfielders$Player, y = midfielders$`Total Assists`, visible = F,type = 'bar',name = "Assists",textposition = 'auto', marker = list(color = 'rgb(58,90,225)', line = list(color = 'rgb(8,48,107)', width = 1.5))) %>%
add_trace( x = forwards$Player, y = forwards$`Total Goals`, visible = F,type = 'bar',name = "Goals",textposition = 'auto', marker = list(color = 'rgb(58,200,225)', line = list(color = 'rgb(8,48,107)', width = 1.5))) %>%
add_trace( x = forwards$Player, y = forwards$`Total Assists`, visible = F,type = 'bar',name = "Assists",textposition = 'auto', marker = list(color = 'rgb(58,90,225)', line = list(color = 'rgb(8,48,107)', width = 1.5))) %>%
add_trace( x = attackingMidfielders$Player, y = attackingMidfielders$`Total Goals`, visible = F,type = 'bar',name = "Goals",textposition = 'auto', marker = list(color = 'rgb(58,200,225)', line = list(color = 'rgb(8,48,107)', width = 1.5))) %>%
add_trace( x = attackingMidfielders$Player, y = attackingMidfielders$`Total Assists`, visible = F,type = 'bar',name = "Assists",textposition = 'auto', marker = list(color = 'rgb(58,90,225)', line = list(color = 'rgb(8,48,107)', width = 1.5))) %>%
add_trace( x = attackingDefenders$Player, y = attackingDefenders$`Total Goals`, visible = F,type = 'bar',name = "Goals",textposition = 'auto', marker = list(color = 'rgb(58,200,225)', line = list(color = 'rgb(8,48,107)', width = 1.5))) %>%
add_trace( x = attackingDefenders$Player, y = attackingDefenders$`Total Assists`, visible = F,type = 'bar',name = "Assists",textposition = 'auto', marker = list(color = 'rgb(58,90,225)', line = list(color = 'rgb(8,48,107)', width = 1.5))) %>%
layout(
title = "Player Goals/Assists Chart (Top 5)" ,
font = list(size = 2),
yaxis = list(title = "Count"),
updatemenus = list(
list(
y = 1.5,
buttons = list(
list(method = "restyle",
args = list("visible", list(T,T,T,F,F,F,F,F,F,F,F,F,F)),
label = "All Positions"),
list(method = "restyle",
args = list("visible", list(T,F,F,T,T,F,F,F,F,F,F,F,F)),
label = "Defenders"),
list(method = "restyle",
args = list("visible", list(T,F,F,F,F,T,T,F,F,F,F,F,F)),
label = "Midfielders"),
list(method = "restyle",
args = list("visible", list(T,F,F,F,F,F,F,T,T,F,F,F,F)),
label = "Forwards"),
list(method = "restyle",
args = list("visible", list(T,F,F,F,F,F,F,F,F,T,T,F,F)),
label = "Attacking Midfielders"),
list(method = "restyle",
args = list("visible", list(T,F,F,F,F,F,F,F,F,F,F,T,T)),
label = "Attacking Defenders")))
))
#Congfigure plotly settings
graph2 <-graph2 %>% layout(xaxis = list(fixedrange = TRUE), yaxis = list(fixedrange =TRUE)) %>% style(hoverlabel = label) %>% layout(font = font) %>% config(displayModeBar = FALSE)
## Warning: No trace type specified and no positional attributes specified
## No trace type specified:
## Based on info supplied, a 'scatter' trace seems appropriate.
## Read more about this trace type -> https://plotly.com/r/reference/#scatter
## No scatter mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
## Warning: Can't display both discrete & non-discrete data on same axis
#Display graph
graph2
## Warning: Can't display both discrete & non-discrete data on same axis
Create tables for interaction
#Assign table length
len <- 5
#Create tables for each dropdown option
topAggressiveEng <- sqldf("select clubAggression, `Club Yellows`, `Club Reds`, club from finalDataFrame where League = 'Premier League' Group by Club ") %>% arrange(desc(clubAggression)) %>% top_n(len, clubAggression)
topAggressiveGer <- sqldf("select Club,ClubAggression, `Club Yellows`, `Club Reds` from finalDataFrame where League = 'Bundesliga' Group by Club ") %>% arrange(desc(clubAggression)) %>% top_n(len, clubAggression)
topAggressiveFra <- sqldf("select Club,ClubAggression, `Club Yellows`, `Club Reds` from finalDataFrame where League = 'Ligue 1' Group by Club ") %>% arrange(desc(clubAggression)) %>% top_n(len, clubAggression)
topAggressiveIta <- sqldf("select Club,ClubAggression, `Club Yellows`,`Club Reds` from finalDataFrame where League = 'Serie A' Group by Club ") %>% arrange(desc(clubAggression)) %>% top_n(len, clubAggression)
topAggressiveSpa <- sqldf("select Club,ClubAggression, `Club Yellows`, `Club Reds` from finalDataFrame where League = 'La Liga' Group by Club ") %>% arrange(desc(clubAggression)) %>% top_n(len, clubAggression)
Create chart to display club aggression
#Configure display settings
font = list(
family = "Arial",
size = 20,
color = "Black"
)
label = list(
bordercolor = "Black",
font = font
)
#Create graph using plotly, this allows for user interaction
graph3 <- plot_ly() %>%
add_trace( x = NULL, y =NULL, visible = F) %>%
add_trace( x = topAggressive$Club, y = topAggressive$`Club Yellows`, visible = T,type = 'bar',name = "Yellows",textposition = 'auto', marker = list(color = 'rgb(255,250,50)', line = list(color = 'rgb(8,48,107)', width = 1.5))) %>%
add_trace( x = topAggressive$Club, y = topAggressive$`Club Reds`, visible = T,type = 'bar',name = "Reds",textposition = 'auto', marker = list(color = 'rgb(255,0,0)', line = list(color = 'rgb(8,48,107)', width = 1.5))) %>%
add_trace( x = topAggressiveEng$Club, y = topAggressiveEng$`Club Yellows`, visible = F,type = 'bar',name = "Yellows",textposition = 'auto', marker = list(color = 'rgb(255,250,50)', line = list(color = 'rgb(8,48,107)', width = 1.5))) %>%
add_trace( x = topAggressiveEng$Club, y = topAggressiveEng$`Club Reds`, visible = F,type = 'bar',name = "Reds",textposition = 'auto', marker = list(color = 'rgb(255,0,0)', line = list(color = 'rgb(8,48,107)', width = 1.5))) %>%
add_trace( x = topAggressiveGer$Club, y = topAggressiveGer$`Club Yellows`, visible = F,type = 'bar',name = "Yellows",textposition = 'auto', marker = list(color = 'rgb(255,250,50)', line = list(color = 'rgb(8,48,107)', width = 1.5))) %>%
add_trace( x = topAggressiveGer$Club, y = topAggressiveGer$`Club Reds`, visible = F,type = 'bar',name = "Reds",textposition = 'auto', marker = list(color = 'rgb(255,0,0)', line = list(color = 'rgb(8,48,107)', width = 1.5))) %>%
add_trace( x = topAggressiveFra$Club, y = topAggressiveFra$`Club Yellows`, visible = F,type = 'bar',name = "Yellows",textposition = 'auto', marker = list(color = 'rgb(255,250,50)', line = list(color = 'rgb(8,48,107)', width = 1.5))) %>%
add_trace( x = topAggressiveFra$Club, y = topAggressiveFra$`Club Reds`, visible = F,type = 'bar',name = "Reds",textposition = 'auto', marker = list(color = 'rgb(255,0,0)', line = list(color = 'rgb(8,48,107)', width = 1.5))) %>%
add_trace( x = topAggressiveIta$Club, y = topAggressiveIta$`Club Yellows`, visible = F,type = 'bar',name = "Yellows",textposition = 'auto', marker = list(color = 'rgb(255,250,50)', line = list(color = 'rgb(8,48,107)', width = 1.5))) %>%
add_trace( x = topAggressiveIta$Club, y = topAggressiveIta$`Club Reds`, visible = F,type = 'bar',name = "Reds",textposition = 'auto', marker = list(color = 'rgb(255,0,0)', line = list(color = 'rgb(8,48,107)', width = 1.5))) %>%
add_trace( x = topAggressiveSpa$Club, y = topAggressiveSpa$`Club Yellows`, visible = F,type = 'bar',name = "Yellows",textposition = 'auto', marker = list(color = 'rgb(255,250,50)', line = list(color = 'rgb(8,48,107)', width = 1.5))) %>%
add_trace( x = topAggressiveSpa$Club, y = topAggressiveSpa$`Club Reds`, visible = F,type = 'bar',name = "Reds",textposition = 'auto', marker = list(color = 'rgb(255,0,0)', line = list(color = 'rgb(8,48,107)', width = 1.5))) %>%
layout(
title = "Most Aggresive clubs (Top 5)" ,
font = list(size = 2),
yaxis = list(title = "Count"),
xaxis = list(title = "Club"),
updatemenus = list(
list(
y = 1.5,
buttons = list(
list(method = "restyle",
args = list("visible", list(T,T,T,F,F,F,F,F,F,F,F,F,F)),
label = "All Leagues"),
list(method = "restyle",
args = list("visible", list(T,F,F,T,T,F,F,F,F,F,F,F,F)),
label = "Premier League"),
list(method = "restyle",
args = list("visible", list(T,F,F,F,F,T,T,F,F,F,F,F,F)),
label = "Bundesliga"),
list(method = "restyle",
args = list("visible", list(T,F,F,F,F,F,F,T,T,F,F,F,F)),
label = "Forwards"),
list(method = "restyle",
args = list("visible", list(T,F,F,F,F,F,F,F,F,T,T,F,F)),
label = "Serie A"),
list(method = "restyle",
args = list("visible", list(T,F,F,F,F,F,F,F,F,F,F,T,T)),
label = "La Liga")))
))
#Congfigure plotly settings
graph3 <- graph3 %>% layout(xaxis = list(fixedrange = TRUE), yaxis = list(fixedrange =TRUE),barmode = 'stack') %>% style(hoverlabel = label) %>% layout(font = font) %>% config(displayModeBar = FALSE)
## Warning: No trace type specified and no positional attributes specified
## No trace type specified:
## Based on info supplied, a 'scatter' trace seems appropriate.
## Read more about this trace type -> https://plotly.com/r/reference/#scatter
## No scatter mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
## Warning: Can't display both discrete & non-discrete data on same axis
#Display graph
graph3
## Warning: Can't display both discrete & non-discrete data on same axis
We set out to answer four different questions. Each question was made to search for niche answers that would be valuable to sports betters/ gamblers. Using the same data and same methodological patterns, more niche information could be drawn from the data in the future. The results in the data of this section varied much more to those in the exploration section which suggests it is more valuable as it is less similar. A better/ gambler could look at the graphs above and use the information to place bets when clubs of the different chosen leagues play each other.
Fbref.com. (n.d.). Retrieved December 4, 2022, from https://fbref.com/en/comps/9/Premier-League-Stats