Skip to content

Instantly share code, notes, and snippets.

@batpigandme
Last active February 25, 2016 15:14
Show Gist options
  • Save batpigandme/0b126af5c23f14f74b40 to your computer and use it in GitHub Desktop.
Save batpigandme/0b126af5c23f14f74b40 to your computer and use it in GitHub Desktop.
EDA with density plot and histograms of nba-stephen-curry three point shooting, base R, and with ggplot2 and ggthemes
## steph curry's three-point shooting data from
## stattleship api
## density plot of three-pt pctg
d <- density(steph_gls$three_pointers_pct)
plot(d, type="n", main="three point percentage")
polygon(d, col="red", border="gray")
## histograms
hist(steph_gls$three_pointers_attempted)
hist(steph_gls$three_pointers_made)
hist(steph_gls$three_pointers_pct)
## plot cumulative attempts and makes in base
## add some room to the margins
par(mar=c(5, 5, 4, 2) + 0.1)
## extend x and y limits to see projection
plot(cumsum(steph_gls$three_pointers_attempted),
cumsum(steph_gls$three_pointers_made),
xlim=c(0, 620), ylim = c(0, 280))
## add ab line using lm(y ~ x)
mod1 <- lm(cumsum(steph_gls$three_pointers_made) ~ cumsum(steph_gls$three_pointers_attempted))
abline(mod1, lwd=.5, col="blue")
## add lines at 600 and 272
abline(v=600, col="red", lty=2)
abline(h=272, col="red", lty=2)
## ggthemes documentation https://github.com/jrnold/ggthemes
library("devtools")
install_github(c("hadley/ggplot2", "jrnold/ggthemes"))
## load the libraries
library("ggplot2")
library("ggthemes")
## three pointers attempted
ggplot(steph_gls aes(three_pointers_attempted)) +
geom_histogram(stat = "bin", binwidth = 1, colour="white") +
ggtitle("Curry 3PA Per Game") +
theme_economist()
## three pointers made
ggplot(steph_gls, aes(three_pointers_made)) +
geom_histogram(stat = "bin", binwidth = 1, colour="white") +
ggtitle("Curry 3PM Per Game") +
theme_economist()
## three pointers pctg
ggplot(steph_gls, aes(three_pointers_pct)) +
geom_histogram(stat = "bin", binwidth = .05, colour="grey") +
ggtitle("Curry 3Pt % By Game") +
theme_economist()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment