Code Monkey home page Code Monkey logo

passing-networks's Introduction

Passing networks using R

Here you can find a couple of R functions to create customized passing networks with both event data by Statsbomb and tracking data by Metrica Sport.

First, i would suggest to read this article in order to get some general context and more details of this work.

Then, you can follow this steps:

1.- Download the files contained in (or pull) this repository, including the codes (*.R files) and the field background images (*.JPG files from "fields" folder).

2.- Get the data

Statsbomb event data

  • Don't forget to read and agree to the User Agreement

  • Get the data using the code of the file "get_SB_event_data_WC2018.R" (save the file "SB_WC_events_clean.RDS" into a folder named "data")

  • If you have any problem with this process you can also review these excellent resources about working with Statsbomb data in R: 1 & 2

Metrica Sport data

3.- Create your passing networks graphs

  • Open the "main_code.R" file, load the necessary packages and call the respective function to create your customized graphs.

  • There are a lot of arguments to configurate the creation and outputs of the passing networks, both data selection and aesthetics parts.

  • Here a code example using Statsbomb data with the function "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)

  • And here a code using Metrica Sport data with the function "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)


This work is in some way a mix of these things:

Future/pending work:

  • Mainly to enable a passes value metric option, like VAEP, xT, g+, EPV or similar

passing-networks's People

Contributors

bustami avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

passing-networks's Issues

issue installing package

hi there, i am getting this error when trying to install the soccermatics package

* installing *source* package ‘soccermatics’ ...
** using staged installation
** R
** data
*** moving datasets to lazyload DB
** byte-compile and prepare package for lazy loading
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : 
  there is no package called ‘xts’
Calls: <Anonymous> ... loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart
Execution halted
ERROR: lazy loading failed for package ‘soccermatics’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/soccermatics’
Error: Failed to install 'soccermatics' from GitHub:
  (converted from warning) installation of package ‘/var/folders/y1/hqdp0znj0hqd3hv020557l8h0000gp/T//RtmphOzfQC/file143f15c0126e0/soccermatics_0.9.4.tar.gz’ had non-zero exit status
In addition: Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
  there is no package called ‘soccermatics

any ideas?

thanks,

james

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.