Instantly share code, notes, and snippets.

# Ed Küpfer edkupfer

Created Aug 27, 2013
Draw a full NBA court in R using ggplot2
View ggplot.nba.fullcourt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 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))+
Last active Apr 25, 2019
Draw a NBA halfcourt in R using ggplot2
View ggplot.nba.halfcourt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 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:
Created Mar 4, 2015
Take shot data from Basketball-Reference player-season page, create ggplot with shot points and isobars
View BRefShotChart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 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("
Last active Dec 21, 2015
Draw a NCAA full basketball court using Lattice
View lattice.ncaa.fullcourt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 # 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)
Last active Dec 21, 2015
Draw a full NBA basketball court in R with lattice
View lattice.nba.fullcourt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 # 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)