expectedpts: Plots expected points of shots as a function of the distance...

Description Usage Arguments Details Value Author(s) References Examples

View source: R/expectedpts.R

Description

Plots expected points of shots as a function of the distance from the basket (default) or another variable

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
expectedpts(
  data,
  var = "shot_distance",
  players = NULL,
  bw = 10,
  period.length = 12,
  palette = gg_color_hue,
  team = TRUE,
  col.team = "gray",
  col.hline = "black",
  xlab = NULL,
  x.range = "auto",
  title = NULL,
  legend = TRUE
)

Arguments

data

a data frame whose rows are field shots and with the following columns: points, event_type, 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, a string giving the name of the numerical variable according to which the expected points are estimated; available options "playlength", "periodTime", "totalTime", "shot_distance" (default).

players

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

bw

numeric, 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).

palette

color palette.

team

logical; if TRUE, draws the expected points for all the shots in data.

col.team

character, color of the expected points line for all the shots in data (default "gray").

col.hline

character, color of the dashed horizontal line (default "black") denoting the expected points for all the shots in data, not conditional to the variable in the x-axis.

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.

legend

logical, 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 field shots have values different from "shot" or "miss" in the even_type 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

1
2
3
4
5
PbP <- PbPmanipulation(PbP.BDB)
PbP.GSW <- subset(PbP, team=="GSW" & !is.na(shot_distance))
plrys <- c("Stephen Curry","Kevin Durant")
expectedpts(data=PbP.GSW, bw=10, players=plrys, col.team='dodgerblue',
        palette=colorRampPalette(c("gray","black")), col.hline="red")

BasketballAnalyzeR documentation built on July 2, 2020, 2:14 a.m.