Skip to content

Instantly share code, notes, and snippets.

Ed Küpfer edkupfer

Block or report user

Report or block edkupfer

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@edkupfer
edkupfer / ggplot.nba.halfcourt
Last active Apr 25, 2019
Draw a NBA halfcourt in R using ggplot2
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:
@edkupfer
edkupfer / ggplot.nba.fullcourt
Created Aug 27, 2013
Draw a full NBA court in R using ggplot2
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))+
@edkupfer
edkupfer / BRefShotChart
Created Mar 4, 2015
Take shot data from Basketball-Reference player-season page, create ggplot with shot points and isobars
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)]
@edkupfer
edkupfer / lattice.ncaa.fullcourt
Last active Dec 21, 2015
Draw a NCAA full basketball court using Lattice
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)
@edkupfer
edkupfer / lattice.nba.fullcourt
Last active Dec 21, 2015
Draw a full NBA basketball court in R with 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)
You can’t perform that action at this time.