Description Usage Arguments Value Examples
Merge the shot chart data with a SpatialPolygonDataFrame representing an NBA regulation half court. This makes it useful to construct a weight matrix that can be used in spatial modeling.
1 | merge_shot_data(shpfile, shot_df, hex = FALSE)
|
shpfile |
SpatialPolygonsDataFrame returned |
shot_df |
Data frame object returned from |
SpatialPolygonsDataFrame object which contains the spatial polygons along with additional data from(shot_df) in the data slot.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | # create a half court raster SpatialPolygonsDataFrame object
sp_pol <- half_court_raster()
# merge shot chart data with the spatial polygon (grid)
sp_pol <- merge_shot_data(sp_pol, NBAapi::shots_cavs)
# plot the result
## first deal with color
colors <- c("white", "black")
num_cols <- length(unique(sp_pol@data$counts))
plotclr <- colorRampPalette(colors)(num_cols)
breaks <- seq(0, max(max(unique(sp_pol@data$counts), na.rm = TRUE)), length.out = num_cols + 1)
colcode <- plotclr[findInterval(sp_pol@data$counts, vec = sort(unique(sp_pol@data$counts)))]
## now plot grid
plot(sp_pol, col = colcode, border = "transparent")
## now plot shots
draw_halfcourt(add = TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.