The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.
This document contains all the needed R code to reproduce the results described in the paper Collection and analysis of Spanish basketball shooting data and a centralized data platform.
# Firstly, load BAwiR and other packages that will be used here:
library(BAwiR)
library(dplyr)
library(Anthropometry)
An example for obtaining the spatial shooting data from the official ACB website is as follows. Define the analyst’s name, user agent and x_apikey accordingly.
data_days <- do_scrape_days_acb("2024", "analyst_name", TRUE, 2)
data_shots <- do_scrape_shots_acb(data_days[1:2, ], TRUE, "user_agent_def", "x_apikey")
BAwiR contains a sample of the shooting data from the ACB 2024-2025 regular season. We can see it with these commands:
Players and teams belonging to the data frame can be obtained with these commands:
The basketball court is divided into 10 zones as follows:
Several filters can be applied with the following function:
The violin and boxplots to investigate the data distributions and statistical summaries are created as follows:
The plot of the shooting patterns of the entire league by zones can be obtained as follows:
The plots with the location of each individual shot attempted by Dylan Ennis and his shooting patterns by zones can be obtained as follows:
df1 <- do_filter_data(df0, "2024-2025", "", "", "", "", "D. Ennis")
shots_stats <- do_shots_stats(df1, df0)
do_viz_shots_scatter(shots_stats, "player", TRUE)
do_viz_shots_scatter(shots_stats, "player", FALSE)
The plots with the comparison of the Ennis’ and league field goal percentage and the heatmap showing the distribution of Ennis’ shot attempts across the court can be obtained as follows:
Finally, the code to create a visualization of the players who shoot little and score a lot in several zones at the same time is the following:
zones_court <- metrics_player_zone %>%
distinct(location) %>%
pull()
numArch <- 10
numRep <- 20
numArchoid <- 2 # Number of archetypoids.
data_arch <- data.frame()
# Run the algorithm for each zone one by one and save the archetypoid
# with least shots and highest percentage.
i <- 1
zone <- metrics_player_zone %>%
filter(location == zones_court[i]) %>%
select(-pps_player)
zone_num <- zone %>%
select(total, perc_player)
lass <- stepArchetypesRawData(data = zone_num, numArch = 1:numArch,
numRep = numRep, verbose = FALSE)
res_ns <- archetypoids(numArchoid, zone_num, huge = 200, step = FALSE,
ArchObj = lass, nearest = "cand_ns",sequ = TRUE)
zone[res_ns$cases, ]
# Here [1, ] indicates the archetypoid of interest. Change it accordingly.
# Here 4 indicates the number of similar players to the archetypoid. Change it accordingly.
arch_targ <- zone[order(res_ns$alphas[1, ], decreasing = TRUE)[1:4], ]
data_arch <- rbind(data_arch, arch_targ)
i <- 2
zone <- metrics_player_zone %>%
filter(location == zones_court[i]) %>%
select(-pps_player)
zone_num <- zone %>%
select(total, perc_player)
lass <- stepArchetypesRawData(data = zone_num, numArch = 1:numArch,
numRep = numRep, verbose = FALSE)
res_ns <- archetypoids(numArchoid, zone_num, huge = 200, step = FALSE,
ArchObj = lass, nearest = "cand_ns",sequ = TRUE)
zone[res_ns$cases, ]
arch_targ <- zone[order(res_ns$alphas[2, ], decreasing = TRUE)[1:4], ]
data_arch <- rbind(data_arch, arch_targ)
do_best_zones(data_arch)
## R version 4.3.3 (2024-02-29)
## Platform: x86_64-redhat-linux-gnu (64-bit)
## Running under: Fedora Linux 39 (Workstation Edition)
##
## Matrix products: default
## BLAS/LAPACK: FlexiBLAS OPENBLAS-OPENMP; LAPACK version 3.11.0
##
## locale:
## [1] LC_CTYPE=es_ES.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=es_ES.UTF-8 LC_COLLATE=C
## [5] LC_MONETARY=es_ES.UTF-8 LC_MESSAGES=es_ES.UTF-8
## [7] LC_PAPER=es_ES.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=es_ES.UTF-8 LC_IDENTIFICATION=C
##
## time zone: Europe/Madrid
## tzcode source: system (glibc)
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## loaded via a namespace (and not attached):
## [1] digest_0.6.37 R6_2.6.1 fastmap_1.2.0 xfun_0.52
## [5] cachem_1.1.0 knitr_1.50 htmltools_0.5.8.1 rmarkdown_2.29
## [9] lifecycle_1.0.4 cli_3.6.5 sass_0.4.10 jquerylib_0.1.4
## [13] compiler_4.3.3 tools_4.3.3 evaluate_1.0.3 bslib_0.9.0
## [17] yaml_2.3.10 rlang_1.1.6 jsonlite_2.0.0
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.