Description Usage Arguments Details Value Author(s) References See Also Examples
Plots different kinds of charts based on shot coordinates
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | shotchart(
data,
x,
y,
z = NULL,
z.fun = median,
result = NULL,
type = NULL,
scatter = FALSE,
num.sect = 7,
n = 1000,
col.limits = c(NA, NA),
courtline.col = "black",
bg.col = "white",
sectline.col = "white",
text.col = "white",
legend = FALSE,
drop.levels = TRUE,
pt.col = "black",
pt.alpha = 0.5,
nbins = 25,
palette = "mixed"
)
|
data |
A data frame whose rows are field shots and columns are half-court shot coordinates x and y, and optionally additional variables to be specified in |
x |
character, indicating the variable name of the x coordinate. |
y |
character, indicating the variable name of the y coordinate. |
z |
character, indicating the name of the variable used to color the points (if |
z.fun |
function (active when |
result |
character (active when |
type |
character, indicating the plot type; available option are |
scatter |
logical, if TRUE a scatter plot of the shots is added to the plot. |
num.sect |
integer (active when |
n |
integer (active when |
col.limits |
numeric vector, (active when |
courtline.col |
color of court lines. |
bg.col |
background color. |
sectline.col |
color of sector lines (active when |
text.col |
color of text annotation within sectors (active when |
legend |
logical, if TRUE a legend for |
drop.levels |
logical, if TRUE unused levels of the |
pt.col |
color of points in the scatter plot. |
pt.alpha |
numeric, transparency of points in the scatter plot. |
nbins |
integer (active when |
palette |
color palette; available options |
The data
dataframe could also be a play-by-play dataset provided that rows corresponding to events different from field shots have missing x
and y
coordinates.
x
and y
coordinates must be expressed in feets; the origin of the axes is positioned at the center of the field.
A ggplot2 object.
Marco Sandri, Paola Zuccolotto, Marica Manisera (basketball.analyzer.help@gmail.com)
P. Zuccolotto and M. Manisera (2020) Basketball Data Science: With Applications in R. CRC Press.
drawNBAcourt
, geom_density_2d
, geom_hex
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | PbP <- PbPmanipulation(PbP.BDB)
subdata <- subset(PbP, player=="Kevin Durant")
subdata$xx <- subdata$original_x/10
subdata$yy <- subdata$original_y/10-41.75
shotchart(data=subdata, x="xx", y="yy", scatter=TRUE)
shotchart(data=subdata, x="xx", y="yy", scatter=TRUE, z="result")
shotchart(data=subdata, x="xx", y="yy", scatter=TRUE, z="result",
bg.col="black", courtline.col="white", palette="hot")
shotchart(data=subdata, x="xx", y="yy", result="result",
type="sectors", sectline.col="gray", text.col="red")
shotchart(data=subdata, x="xx", y="yy", z="playlength", result="result",
type="sectors", num.sect=5)
shotchart(data=subdata, x="xx", y="yy", type="density-polygons", palette="bwr")
shotchart(data=subdata, x="xx", y="yy", type="density-raster",
scatter=TRUE, pt.col="tomato", pt.alpha=0.1)
shotchart(data=subdata, x="xx", y="yy", type="density-hexbin", nbins=30)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.