Skip to content

Instantly share code, notes, and snippets.

@mikeleeco
Last active April 27, 2016 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeleeco/0468a4472b10c5538e2e3d919ca57fe8 to your computer and use it in GitHub Desktop.
Save mikeleeco/0468a4472b10c5538e2e3d919ca57fe8 to your computer and use it in GitHub Desktop.
draft_odds_team
1 2 3 4 5 6 7 8 9 10 11 12 13 14
PHI 0.268 0.226 0.182 0.625 0.1
PHX 0.12 0.127 0.133 0.091 0.35 0.16 0.013 0.961 0.018
BOS 0.156 0.157 0.156 0.244 0.26 0.042
LAL 0.197 0.187 0.171
MIN 0.089 0.098 0.108 0.28 0.358 0.083 0.005
NOP 0.064 0.072 0.081 0.44 0.302 0.04 0.001
DEN 0.061 0.069 0.08 0.602 0.14 0.01 0
MIL 0.019 0.02 0.026 0.26 0.325 0.333 0.03 0.002 0
SAC 0.011 0.023 0.04 0.01 0.255 0.329 0.34 0
TOR 0.001 0.004 0.3 0.335 0.327 0.03 0
ORL 0.008 0.01 0.011 0.91 0.062 0.001
UTA 0.007 0.009 0.01 0.936 0.038 0
WAS 0.006 0.007 0.008
CHI 0.005 0.006 0.007 0.03 0.982
#devtools::install_github("hadley/ggplot2")
#devtools::install_github("hadley/tidyr")
library(ggplot2)
library(tidyr)
library(RColorBrewer)
odds <- read.csv("odds_team.csv")
odds <- gather(odds, X)
odds[,2] <- substring(odds[,2], 2)
colnames(odds) <- c("Team","Pick","Probability")
odds$Pick <- as.numeric(odds$Pick)
odds$Team <- as.character(odds$Team)
odds$Selecting <- ifelse(odds$Team=="LAL" & odds$Pick > 3,"PHI",ifelse(odds$Team=="SAC" & odds$Pick > 10,"CHI",ifelse(odds$Team=="WAS" & odds$Pick > 3,"PHX",odds$Team)))
odds$Selecting <- factor(odds$Selecting, levels=c("PHI", "PHX", "BOS", "LAL", "MIN", "NOP", "DEN","MIL", "SAC", "TOR", "ORL", "UTA", "CHI","WAS"))
odds$Pick <- factor(odds$Pick, levels = c(14:1))
odds$Probability <- ifelse(is.na(odds$Probability),0,odds$Probability)
g <- ggplot(odds, aes(Pick))
g <- g + geom_bar(aes(x = Pick, y = Probability, fill = Selecting),alpha=0.9,color="white",stat="identity")
g <- g + scale_y_continuous(limits=c(0, 1), expand = c(0, 0),breaks = seq(0, 1, by = 0.1),1,name="Probability", labels=scales::percent) +
labs(x=NULL, y=NULL, title="2016 NBA Draft Lottery Probabilities",
subtitle = "Alternative, pick oriented view. After tiebreakers, pick trades, and swaps. Based on 100,000 simulations.",
caption="Reproduced by: @mikeleeco Original: @dsparks Source: http://www.nba.com/celtics/news/sidebar/2016-draft-lottery-qa") +
coord_flip() +
scale_fill_manual(name="Pick",values = c("#006BB6", "#E56020","#008348", "#FDB927", "#C4CED3","#B4975A", "#4FA8FF","#F0EBD2", "#724C9F", "#061922","#007DC5", "#00471B", "#CE1141", "#002B5C"))
g + theme(
axis.text.x = element_text(size=14,margin=margin(b=5),color = "black"),
axis.title.x = element_text(size=16),
plot.title = element_text(size=30),
plot.subtitle = element_text(size=14),
plot.caption = element_text(size=16,face = "italic",hjust=.5,margin=margin(t=5)),
axis.text.y = element_text(size=18,colour = "black"),
axis.ticks.y=element_blank(),
axis.ticks.x=element_blank(),
panel.border=element_blank(),
panel.grid.major.x=element_line(color="#2b2b2b", linetype="dotted", size=0.15),
panel.grid.major.y=element_blank(),
legend.text = element_text(size=14),
legend.title = element_text(size=18),
legend.key = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
strip.background = element_blank(),
panel.background = element_blank()
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment