-
Notifications
You must be signed in to change notification settings - Fork 15
/
main_code.R
47 lines (36 loc) · 1.83 KB
/
main_code.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# loading or installing packages
if(!require(dplyr)){install.packages("dplyr")}
library(dplyr)
if(!require(grid)){install.packages("grid")}
library(grid)
if(!require(splancs)){install.packages("splancs")}
library(splancs)
if(!require(ggplot2)){install.packages("ggplot2")}
library(ggplot2)
if(!require(ggrepel)){install.packages("ggrepel")}
library(ggrepel)
if(!require(readr)){install.packages("readr")}
library(readr)
if(!require(scales)){install.packages("scales")}
library(scales)
if (!require("devtools")) install.packages("devtools")
library(devtools)
if(!require(soccermatics)){devtools::install_github("jogall/soccermatics")}
library(soccermatics)
# Example 1: Statsbomb data
## Get the data using the code in the file "get_SB_event_data_WC2018.R"
source("soccerPassNetEventing.R")
soccerPassNetEventing(gameID = 7584, TeamName = "Japan", poss = T, pass_dir = T, convex = T,
minPass = 5, node_pos = "origin", nodeFill = "blue", edgeAlpha = 0.5,
label = T, shortNames = T, maxNodeSize = 15, maxEdgeSize = 2.5,
Flipx = F, field = 1)
ggsave("plots/Japan-Belgium-ver2.png", width = 15, height = 10, units = "in", device = "png")
# Example 2: Metrica Sport data
## Get the data from this repository: https://github.com/metrica-sports/sample-data
source("soccerPassNetTracking.R")
soccerPassNetTracking(gameID = "1", TeamName = "Home", pos_source = "track", node_pos = "origin",
context = "attacking", half = "own", field = 2,
pass_dir = T, minPass = 2, convex = T,
label = T, shortNames = F, labelSize = 2,
maxNodeSize = 12, maxEdgeSize = 1.5, edgeAlpha = 0.8)
ggsave("1-Home-attack-own-ver2.png", width = 15, height = 10, units = "in", device = "png")