scoringprob {BasketballAnalyzeR}R Documentation

Plots scoring probability of shots as a function of a given variable

Description

Plots scoring probability of shots as a function of a given variable

Usage

scoringprob(
  data,
  var,
  shot.type,
  players = NULL,
  bw = 20,
  period.length = 12,
  xlab = NULL,
  x.range = "auto",
  title = NULL,
  palette = gg_color_hue,
  team = TRUE,
  col.team = "dodgerblue",
  legend = TRUE
)

Arguments

data

a data frame whose rows are shots and with the following columns: result, ShotType, player (only if the players argument is not NULL) and at least one of playlength, periodTime, totalTime, shot_distance (the column specified in var, see Details).

var

character, the string giving the name of the numerical variable according to which the scoring probability is estimated. Available options: "playlength", "periodTime", "totalTime", "shot_distance".

shot.type

character, the type of shots to be analyzed; available options: "2P", "3P", "FT", "field".

players

subset of players to be displayed (optional; it can be used only if the player column is present in data).

bw

numeric, the smoothing bandwidth of the kernel density estimator (see ksmooth).

period.length

numeric, the length of a quarter in minutes (default: 12 minutes as in NBA).

xlab

character, x-axis label.

x.range

numerical vector or character; available options: NULL (x-axis range defined by ggplot2, the default), "auto" (internally defined x-axis range), or a 2-component numerical vector (user-defined x-axis range).

title

character, plot title.

palette

color palette.

team

character; if TRUE draws the scoring probability for all the shots in data.

col.team

character, color of the scoring probability line for all the shots in data.

legend

character; if TRUE, color legend is displayed (only when players is not NULL).

Details

The data data frame could also be a play-by-play dataset provided that rows corresponding to events different from shots have NA in the ShotType variable.

Required columns:

Value

A ggplot2 plot

Author(s)

Marco Sandri, Paola Zuccolotto, Marica Manisera (basketballanalyzer.help@unibs.it)

References

P. Zuccolotto and M. Manisera (2020) Basketball Data Science: With Applications in R. CRC Press.

Examples

PbP <- PbPmanipulation(PbP.BDB)
PbP.GSW <- subset(PbP, team=="GSW" & result!="")
players <- c("Kevin Durant","Draymond Green","Klay Thompson")
scoringprob(data=PbP.GSW, shot.type="2P", players=players,
            var="shot_distance", col.team="gray")

[Package BasketballAnalyzeR version 0.5.0 Index]