Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GMTool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
margarr
GMTool
Commits
a912d353
Commit
a912d353
authored
Jun 14, 2022
by
Mario Garrido Tapias
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
BivariateAnalysis.R
+36
-9
36 additions, 9 deletions
BivariateAnalysis.R
with
36 additions
and
9 deletions
BivariateAnalysis.R
+
36
−
9
View file @
a912d353
...
...
@@ -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
))
L
aLigaPlayersStudyStand
<-
as.
data.frame
(
scale
(
laLigaPlayersStudy
))
correlacion
<-
round
(
cor
(
L
aLigaPlayersStudyStand
),
1
)
p.mat
<-
cor_pmat
(
L
aLigaPlayersStudyStand
)
l
aLigaPlayersStudyStand
<-
data.frame
(
scale
(
laLigaPlayersStudy
))
correlacion
<-
round
(
cor
(
l
aLigaPlayersStudyStand
),
1
)
p.mat
<-
cor_pmat
(
l
aLigaPlayersStudyStand
)
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"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment