Skip to content

Instantly share code, notes, and snippets.

@rudeboybert
Last active November 7, 2016 16:06
Show Gist options
  • Save rudeboybert/97c0642fe5dd977804cb7299b8be299c to your computer and use it in GitHub Desktop.
Save rudeboybert/97c0642fe5dd977804cb7299b8be299c to your computer and use it in GitHub Desktop.
# Probability Clinton Wins -- bookie odds 11.07.16
# Code by Jay Emerson for scraping data off web page, and displaying
z <- scan('https://electionbettingodds.com', what="", sep="\n")
z <- z[grep("in last day", z)]
z <- gsub("<[^<>]*>", ",", z)
z <- gsub("^.*',(.*):.*,Clinton ([0-9.]*)%.*$", "\\1,\\2", z)[-1]
writeLines(z, "betfair.csv")
z <- read.csv("betfair.csv", as.is=TRUE, header=FALSE)
names(z) <- c("state", "pclinton")
library(ggplot2)
library(dplyr)
ggplot(z, aes(x=reorder(state,pclinton), y=pclinton)) +
geom_bar(stat="identity") +
geom_hline(yintercept=50, col="red") +
labs(x="State", y="Probability Clinton") +
coord_flip()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment