Last active
November 7, 2016 16:06
-
-
Save rudeboybert/97c0642fe5dd977804cb7299b8be299c to your computer and use it in GitHub Desktop.
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
# 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