Skip to content
Snippets Groups Projects
Commit a912d353 authored by Mario Garrido Tapias's avatar Mario Garrido Tapias
Browse files

Scatter corr plot with new colour argument and 1st elimination of correlated variables

parent cd9a2de0
No related branches found
No related tags found
No related merge requests found
......@@ -23,7 +23,7 @@ puntos2d <- function(variableEnX, variableEnY, datos, temporada, color) {
}
# Scatter plot for 2 variables with their correlation and regression line
scatterForCorr <- function(datos, variableX, variableY, season) {
scatterForCorr <- function(datos, variableX, variableY, season, col) {
if(missing(season)) {
X <- paste(variableX, sep = "")
Y <- paste(variableY, sep = "")
......@@ -37,10 +37,11 @@ scatterForCorr <- function(datos, variableX, variableY, season) {
sp <- ggscatter(datos, x = X, y = Y,
add = "reg.line", # Add regressin line
add.params = list(color = "#00688B", fill = "lightgray"), # Customize reg. line
add.params = list(color = col, fill = "lightgray"), # Customize reg. line
conf.int = TRUE # Add confidence interval
)
sp + stat_cor(method = "pearson", label.x = medianX, label.y = maxY+10)
sp + stat_cor(method = "pearson", label.x = medianX, label.y = maxY+1.5) +
xlab(titleForYAxis(variableX)) + ylab(titleForYAxis(variableY))
}
#############
......@@ -152,21 +153,26 @@ sp + stat_cor(method = "pearson", label.x = , label.y = 30)
######################################
# SELECCION DE LAS VARIABLES FINALES #
######################################
# 1era SELECCION
# Quitamos: "passes_completed.", "passes_received.", "shots_on_target.", "dribbles_completed.",
# "tackles_won","aerials_won.", "pens_made.", "pens_saved.", "pens_allowed.",
variables <- c("xa.", "passes.", "passes_pct.", "passes_total_distance.", "assisted_shots.", "passes_switches.",
"pass_targets.", "passes_received_pct.", "passes_pressure.",
"xg.", "npxg.", "shots_total.", "shots_on_target_pct.", "goals_per_shot.", "pens_att.", "pens_made_pct.",
"xg.", "npxg.", "shots_total.", "shots_on_target_pct.", "pens_att.", "pens_made_pct.",
"dribbles.", "dribbles_completed_pct.", "goals_assists_per90.",
"sca_passes_dead.", "gca_passes_dead.", "sca_passes_live.", "gca_passes_live.", "sca_dribbles.", "gca_dribbles.", "sca_fouled.", "gca_fouled.",
"passes_intercepted.", "ball_recoveries.", "pressure_regains.", "fouls.", "tackles.", "tackles_pct.", "aerials_contested.", "aerials_won_pct.",
"goals_against_per90_gk.", "pens_played.", "pens_saved_pct.", "shots_on_target_against.", "saves.", "save_pct.")
laLigaPlayersStudy <- laLigaPlayers %>% select(all_off(variables))
globalColNames <- c()
for (variable in variables) {
variable <- gsub("\\.", "", variable)
globalColNames <- c(globalColNames, variable)
}
laLigaPlayersStudy <- laLigaPlayersStudy %>% select(all_of(globalColNames))
laLigaPlayersStudy <- data.frame(lapply(laLigaPlayersStudy, as.numeric))
LaLigaPlayersStudyStand <- as.data.frame(scale(laLigaPlayersStudy))
correlacion <- round(cor(LaLigaPlayersStudyStand), 1)
p.mat <- cor_pmat(LaLigaPlayersStudyStand)
laLigaPlayersStudyStand <- data.frame(scale(laLigaPlayersStudy))
correlacion <- round(cor(laLigaPlayersStudyStand), 1)
p.mat <- cor_pmat(laLigaPlayersStudyStand)
mypalette <- brewer.pal(n = 3, name = 'BuPu')
ggcorrplot(correlacion, type = "upper",
title = "Matriz de correlaciones ordenada",
......@@ -174,9 +180,30 @@ ggcorrplot(correlacion, type = "upper",
pch.cex = 1.2, lab_size = 2.5, tl.cex = 9,
colors = mypalette, ggtheme = ggplot2::theme_gray, p.mat = p.mat, insig = "blank")
###########
# NIVEL 1 #
###########
scatterForCorr(laLigaPlayersStudy, "passes_total_distance", "passes", col = "#9A32CD")
scatterForCorr(laLigaPlayersStudy, "npxg", "xg", col = "#CDC673")
scatterForCorr(laLigaPlayersStudy, "sca_passes_live", "assisted_shots", col = "#9A32CD")
scatterForCorr(laLigaPlayersStudy, "save_pct", "goals_against_per90_gk", col = "#40E0D0")
scatterForCorr(laLigaPlayersStudy, "saves", "shots_on_target_against", col = "#40E0D0")
# 2nda SELECCION
# Quitamos: "passes_total_distance.", "xg.", "assisted_shots.", "goals_against_per90_gk.", "shots_on_target_against.",
variables <- c("xa.", "passes.", "passes_pct.", "passes_switches.",
"pass_targets.", "passes_received_pct.", "passes_pressure.",
"npxg.", "shots_total.", "shots_on_target_pct.", "pens_att.", "pens_made_pct.",
"dribbles.", "dribbles_completed_pct.", "goals_assists_per90.",
"sca_passes_dead.", "gca_passes_dead.", "sca_passes_live.", "gca_passes_live.", "sca_dribbles.", "gca_dribbles.", "sca_fouled.", "gca_fouled.",
"passes_intercepted.", "ball_recoveries.", "pressure_regains.", "fouls.", "tackles.", "tackles_pct.", "aerials_contested.", "aerials_won_pct.",
"pens_played.", "pens_saved_pct.", "saves.", "save_pct.")
# Paradas contra Tiros a puerta en contra
goalkeepers <- laLigaPlayers[which(laLigaPlayers$position.1718 == "GK"),]
datos <- laLigaPlayers[which(laLigaPlayers$position.1718 == "GK")]
puntos2d("saves",
"shots_on_target_against",
goalkeepers, "1718", "firebrick3")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment