Skip to content

Instantly share code, notes, and snippets.

@mikeleeco
Last active April 29, 2016 04:31
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/d872c01d615aaf778da1a1bfd6606042 to your computer and use it in GitHub Desktop.
Save mikeleeco/d872c01d615aaf778da1a1bfd6606042 to your computer and use it in GitHub Desktop.
nhl_draft_odds
1 2 3 4 5 6 7 8 9 10 11 12 13 14
TOR 20 17.5 15 47.5
EDM 13.5 13 12.5 35.2 25.8
VAN 11.5 11.4 11.3 14.2 37.8 13.8
CBJ 9.5 9.7 9.8 3.1 27.3 33.2 7.4
CGY 8.5 8.8 9 9.1 35.5 25.4 3.7
WPG 7.5 7.8 8.2 17.5 39.3 18 1.7
ARI 6.5 6.9 7.2 27.9 39.1 11.6 0.8
BUF 6 6.4 6.8 39.2 34.8 6.6 0.2
MTL 5 5.4 5.6 51.9 28.6 3.4 0.1
COL 3.5 3.8 4.2 64 22.8 1.6 0.1
NJD 3 3.3 3.6 73.6 15.9 0.6 0
OTT 2.5 2.7 3 82.4 9.3 0.1
CAR 2 2.2 2.5 90 3.3
BOS 1 1.1 1.3 96.6
#devtools::install_github("hadley/ggplot2")
#devtools::install_github("hadley/tidyr")
library(ggplot2)
library(tidyr)
library(RColorBrewer)
odds <- read.csv("odds.csv")
odds <- gather(odds, X)
odds[,2] <- substring(odds[,2], 2)
colnames(odds) <- c("Team","Pick","Probability")
odds$Pick <- as.numeric(odds$Pick)
odds$Probability <- as.numeric(odds$Probability) * .01
odds$Team <- as.character(odds$Team)
odds$Team <- factor(odds$Team, levels = odds[1:14,1])
odds$Team <- factor(odds$Team, levels=rev(levels(odds$Team)))
odds$Pick <- factor(odds$Pick, levels = 1:14)
getPalette = colorRampPalette(brewer.pal(11, "Spectral"))(14)
odds$Probability <- ifelse(is.na(odds$Probability),0,odds$Probability)
g <- ggplot(odds, aes(Team))
g <- g + geom_bar(aes(x = Team, y = Probability, fill = Pick),alpha=0.9,stat="identity")
g <- g + scale_y_continuous(expand = c(0, 0), breaks = seq(0, 1, by = 0.1),1,name="Probability", labels=scales::percent) +
labs(x=NULL, y=NULL, title="2016 NHL Draft Lottery Probabilities",
caption="@mikeleeco") +
coord_flip() +
scale_fill_manual(values = getPalette)
g <- g + theme(
axis.text.x = element_text(size=14,margin=margin(b=5),color = "black"),
axis.title.x = element_text(size=18),
plot.subtitle = element_text(size=14),
plot.caption = element_text(size=18,margin = margin(t=2, b=5),face = "italic"),
axis.text.y = element_text(size=18,colour = "black"),
axis.ticks.y=element_blank(),
axis.ticks.x=element_blank(),
plot.title = element_text(size=30,margin = margin(b=10)),
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_rect(fill="#DCDCDC",colour = "#DCDCDC"),
legend.background = element_rect(fill="#DCDCDC"),
panel.background = element_rect(fill="#DCDCDC"),
plot.background = element_rect(fill="#DCDCDC")
)
g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment