Instantly share code, notes, and snippets.

View BRefShotChart
library(ggplot2)
library(stringr)
library(plyr)
library(car)
### the url of the player-season shooting page from basketball reference
url="http://www.basketball-reference.com/players/b/bryanko01/shooting/2015/"
dat=readLines(url)
dat=dat[grep("<div style=\"position:absolute;top:",dat)]
View ggplot.nba.fullcourt
library(ggplot2)
ggplot(data=data.frame(x=1,y=1),aes(x,y))+
###outside box:
geom_path(data=data.frame(x=c(-25,-25,25,25,-25),y=c(-47,47,47,-47,-47)))+
###halfcourt line:
geom_path(data=data.frame(x=c(-25,25),y=c(0,0)))+
###halfcourt semicircle:
geom_path(data=data.frame(x=c(-6000:(-1)/1000,1:6000/1000),y=c(sqrt(6^2-c(-6000:(-1)/1000,1:6000/1000)^2))),aes(x=x,y=y))+
geom_path(data=data.frame(x=c(-6000:(-1)/1000,1:6000/1000),y=-c(sqrt(6^2-c(-6000:(-1)/1000,1:6000/1000)^2))),aes(x=x,y=y))+
View ggplot.nba.halfcourt
library(ggplot2)
ggplot(data=data.frame(x=1,y=1),aes(x,y))+
###outside box:
geom_path(data=data.frame(x=c(-25,-25,25,25,-25),y=c(0,47,47,0,0)))+
###solid FT semicircle above FT line:
geom_path(data=data.frame(x=c(-6000:(-1)/1000,1:6000/1000),y=c(19+sqrt(6^2-c(-6000:(-1)/1000,1:6000/1000)^2))),aes(x=x,y=y))+
###dashed FT semicircle below FT line:
geom_path(data=data.frame(x=c(-6000:(-1)/1000,1:6000/1000),y=c(19-sqrt(6^2-c(-6000:(-1)/1000,1:6000/1000)^2))),aes(x=x,y=y),linetype='dashed')+
###key:
View lattice.ncaa.fullcourt
# NCAA courts are 50ft sideline-to-sideline
# and 94ft end to end. This will plot a court
# with the sidelines on the y-axis, centered
# on the halfcourt circle. Measurement units
# are in feet. The basket at the bottom is
# centered on {x = 0, y = -41.75} and at the
# top on {x = 0, y = 41.75}
library(lattice)
View lattice.nba.fullcourt
# NBA courts are 50ft sideline-to-sideline
# and 94ft end to end. This will plot a court
# with the sidelines on the y-axis, centered
# on the halfcourt circle. Measurement units
# are in feet. The basket at the bottom is
# centered on {x = 0, y = -41.75} and at the
# top on {x = 0, y = 41.75}
library(lattice)