Created
November 6, 2012 20:41
-
-
Save jebyrnes/4027380 to your computer and use it in GitHub Desktop.
MA Senate Projection
This file contains hidden or 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
#load the excellent methods to query polls | |
#linked to at http://alandgraf.blogspot.com/2012/11/quick-post-about-getting-and-plotting.html | |
source("https://raw.github.com/dlinzer/pollstR/master/pollsterAPI.R") | |
#get the MA Senate Race | |
datMass <- pollstR(chart="2012-massachusetts-senate-brown-vs-warren",pages="all") | |
#reshape the data for plotting | |
library(reshape2) | |
dm <- melt.data.frame(datMass, id.vars=c("start.date", "N"), measure.vars=c("Warren", "Brown")) | |
#plot the whole thing and fit a loess curve | |
qplot(start.date, value, data=dm, size=N, color=variable, group=variable) + | |
theme_bw() + | |
scale_color_manual("Candidate", values=c("blue", "red")) + | |
scale_size_continuous("Sample Size") + | |
stat_smooth(aes(weight=N)) + | |
xlab("Poll Start Date") + | |
ylab("Percentage") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment