The data in this report (unless otherwise noted) comes from using the pollstR package. It allows for direct access to the HuffPost Pollster API using R. The code for this report appears on Github.
The current estimate on October 13, 2016.
setwd("~/Dropbox/DataScience/Projects/Election2016")
library(pollstR)
# Chart name for various national polls.
slug <- "2016-general-election-trump-vs-clinton-vs-johnson"
source("Election2016_EstTable.R")
candidate.DT
The line represents HuffPost Pollster’s estimate for overall support based on polling data.
source("Election2016_Polls.R")
est.plotly
National support for the two main US presidential candidates according to various polling organizations.
# Comes from `Election2016_Polls.R` script.
polls.plotly
This is the current electoral map according to estimates by HuffPost Pollster. Estimates are made for states with sufficient polling data.
source("Election2016_ElectoralMap.R")
election.map
The record begins on July 31, 2016 (100 days until Election Day) and includes all public events announced by the respective campaigns. The information is being scraped daily from here and here with the aid of the rvest package.
What appears below may not be entirely accurate because the automated scraping process does not identify cancellations and schedule changes. It merely records planned events.
source("Election2016_ScheduleScrape.R")
source("Election2016_TourMap.R")
map.today
schedule.state <- "US"
schedule.date.begin <- Sys.Date()
schedule.date.end <- Sys.Date()
source("Election2016_ScheduleTable.R")
schedule.DT
# See scripts
# `Election2016_ScheduleScrape.R`
# `Election2016_TourMap.R`
# for source.
map.yesterday
schedule.state <- "US"
schedule.date.begin <- Sys.Date() - 1
schedule.date.end <- Sys.Date() - 1
source("Election2016_ScheduleTable.R")
schedule.DT
# See scripts
# `Election2016_ScheduleScrape.R`
# `Election2016_TourMap.R`
# for source.
map.last3days
schedule.state <- "US"
schedule.date.begin <- Sys.Date() - 2
schedule.date.end <- Sys.Date()
source("Election2016_ScheduleTable.R")
schedule.DT
# See scripts
# `Election2016_ScheduleScrape.R`
# `Election2016_TourMap.R`
# for source.
map.last7days
schedule.state <- "US"
schedule.date.begin <- Sys.Date() - 6
schedule.date.end <- Sys.Date()
source("Election2016_ScheduleTable.R")
schedule.DT
# See scripts
# `Election2016_ScheduleScrape.R`
# `Election2016_TourMap.R`
# for source.
map.last30days
schedule.state <- "US"
schedule.date.begin <- Sys.Date() - 29
schedule.date.end <- Sys.Date()
source("Election2016_ScheduleTable.R")
schedule.DT
# See scripts
# `Election2016_ScheduleScrape.R`
# `Election2016_TourMap.R`
# for source.
map.100days
schedule.state <- "US"
schedule.date.begin <- as.Date("2016-07-31")
schedule.date.end <- Sys.Date()
source("Election2016_ScheduleTable.R")
schedule.DT
library(plotly)
library(plyr)
library(dplyr)
setwd("~/Dropbox/DataScience/Projects/Election2016")
# Create file name which contains yesterday's date
file.name <- paste0("Election2016_csv/Election2016_TourSchedule",
format(Sys.Date(), "%b%d"),
".csv")
# Load file whose name contains yesterday's date
# Note that it is located in a different file than the current working
# directory
schedule.df <- read.csv(file=file.name, stringsAsFactors=FALSE)
pie.party.df <- schedule.df %>%
group_by(state, party) %>%
summarise(count = n())
state.abb[51] <- "DC"
state.name[51] <- "Washington D.C."
# Change from state abbreviation to full name
pie.party.df$name <- sapply(pie.party.df$state, FUN = function(x) {
state.name[which(x == state.abb)]
}) %>% unlist
# pie.dem.df <- filter(pie.party.df, party == "Democratic") %>%
# arrange(desc(count)) %>%
# as.data.frame %>%
# mutate(hover = paste0(name, " (", count, ")"))
pie.party.df <- arrange(pie.party.df, party, desc(count)) %>%
as.data.frame %>%
mutate(hover = paste0(name, " (", count, ")"))
pie.dem.df <- pie.party.df %>%
filter(party == "Democratic")
pie.repub.df <- pie.party.df %>%
filter(party == "Republican")
pie.dem.df <- rbind(pie.dem.df %>% slice(1:7) %>%
mutate(hover = paste(name, "<br>", paste(count, "events"))),
data.frame(state = "other",
party = "Democratic",
count = sum(pie.dem.df$count[8:nrow(pie.dem.df)]),
name = "other",
hover = paste(pie.dem.df$hover[8:nrow(pie.dem.df)],
collapse = "<br>"))
)
pie.repub.df <- rbind(pie.repub.df %>% slice(1:7) %>%
mutate(hover = paste(name, "<br>", paste(count, "events"))),
data.frame(state = "other",
party = "Republican",
count = sum(pie.repub.df$count[8:nrow(pie.repub.df)]),
name = "other",
hover = paste(pie.repub.df$hover[8:nrow(pie.repub.df)], collapse = "<br>")
)
)
plot_ly(data = pie.dem.df,
labels=state,
values=count,
text = hover,
textinfo = "label", # labeling on chart
hoverinfo = "text+percent",
type="pie",
direction = "clockwise",
sort = FALSE,
hole=0.5,
domain = list(x = c(0, 0.4), y = c(0.15, 1)),
marker = list(colors = c('rgb(15,95,160)', 'rgb(33,113,181)',
'rgb(66,146,198)', 'rgb(107,174,214)',
'rgb(158,202,225)', 'rgb(198,219,239)',
'rgb(222,235,247)', 'rgb(235,245,252)')),
showlegend = FALSE) %>%
add_trace(data = pie.repub.df,
labels=state,
values=count,
text = hover,
textinfo = "label", # labeling on chart
hoverinfo = "text+percent",
type="pie",
direction = "clockwise",
sort = FALSE,
hole=0.5,
domain = list(x = c(0.55, 0.95), y = c(0.15, 1)),
marker = list(colors = c('rgb(165,15,21)', 'rgb(203,24,29)',
'rgb(239,59,44)', 'rgb(251,106,74)',
'rgb(252,146,114)', 'rgb(252,187,161)',
'rgb(254,224,210)','rgb(255,245,240)')),
showlegend = FALSE) %>%
layout(title = "Campaign Focus by Party",
annotations = list(
list(x = 0.13 , y = .99, showarrow = F,
text = "Democrats", font = list(size = 18)),
list(x = 0.84 , y = .99, showarrow = F,
text = "Republicans", font = list(size = 18)),
list(x = 0.16 , y = .17, showarrow = F,
text = paste("Total:", sum(pie.dem.df$count)),
font = list(size = 14)),
list(x = 0.81 , y = .17, showarrow = F,
text = paste("Total:", sum(pie.repub.df$count)),
font = list(size = 14))
)
)
Note: Totals include events held by the vice-presidential candidates. Observations: The Trump campaign has focused on holding large rallies to motivate voters, which partially explains why Donald Trump and Mike Pence have held significantly more events than their Democratic counterparts. In contrast, the strategy of the Clinton team has been to focus on a data-driven campaign which targets individual voters and contacts them through local field offices. Additionally, August was a quiet month for Hillary Clinton as she spent a considerable amount of time at private fundraising events.
It is also worth noting that the Republican presidential ticket has visited many more states than Democrats have visited. This has been a cause for some exasperation for seasoned Republican operatives since some of these states are ones that Trump has almost zero chance of winning (e.g. Connecticut, Maryland) or losing (e.g. Texas, Louisiana, Missouri, Mississippi).
There are roughly eleven swing states.
A source within the Trump campaign identified four must-win states: Ohio, Pennsylvania, Florida, and North Carolina.
Present Polling Estimate for Florida on October 13, 2016
slug <- "2016-florida-presidential-general-election-trump-vs-clinton"
source("Election2016_EstTable.R")
candidate.DT
# Overlay estimates with polling data
source("Election2016_Polls.R")
est.plotly
#source("Election2016_Est.R")
# Polling data
polls.plotly
schedule.state <- "FL"
source("Election2016_ScheduleTable.R")
schedule.DT
Present Polling Estimate for North Carolina on October 13, 2016
slug <- "2016-north-carolina-president-trump-vs-clinton"
source("Election2016_EstTable.R")
candidate.DT
# Overlay estimates with polling data
source("Election2016_Polls.R")
est.plotly
#source("Election2016_Est.R")
# Polling data
polls.plotly
schedule.state <- "NC"
source("Election2016_ScheduleTable.R")
schedule.DT
Present Polling Estimate for Ohio on October 13, 2016
slug <- "2016-ohio-president-trump-vs-clinton"
source("Election2016_EstTable.R")
candidate.DT
# Overlay estimates with polling data
source("Election2016_Polls.R")
est.plotly
#source("Election2016_Est.R")
# Polling data
polls.plotly
schedule.state <- "OH"
source("Election2016_ScheduleTable.R")
schedule.DT
While races are typically close in Pennsylvania, Democrats have won this state in the past six presidential elections. The Republicans’ last victory here was in 1988.
Present Polling Estimate for Pennsylvania on October 13, 2016
slug <- "2016-pennsylvania-president-trump-vs-clinton"
source("Election2016_EstTable.R")
candidate.DT
# Overlay estimates with polling data
source("Election2016_Polls.R")
est.plotly
#source("Election2016_Est.R")
# Polling data
polls.plotly
schedule.state <- "PA"
source("Election2016_ScheduleTable.R")
schedule.DT
Present Polling Estimate for Colorado on October 13, 2016
slug <- "2016-colorado-president-trump-vs-clinton"
source("Election2016_EstTable.R")
candidate.DT
# Overlay estimates with polling data
source("Election2016_Polls.R")
est.plotly
#source("Election2016_Est.R")
# Polling data
polls.plotly
schedule.state <- "CO"
source("Election2016_ScheduleTable.R")
schedule.DT
Present Polling Estimate for Iowa on October 13, 2016
slug <- "2016-iowa-president-trump-vs-clinton"
source("Election2016_EstTable.R")
candidate.DT
source("Election2016_Polls.R")
# Overlay estimates with polling data
est.plotly
#source("Election2016_Est.R")
# Polling data
polls.plotly
schedule.state <- "IA"
source("Election2016_ScheduleTable.R")
schedule.DT
Present Polling Estimate for Michigan on October 13, 2016
slug <- "2016-michigan-president-trump-vs-clinton"
source("Election2016_EstTable.R")
candidate.DT
# Overlay estimates with polling data
source("Election2016_Polls.R")
est.plotly
#source("Election2016_Est.R")
# Polling data
polls.plotly
schedule.state <- "MI"
source("Election2016_ScheduleTable.R")
schedule.DT
Present Polling Estimate for Nevada on October 13, 2016
slug <- "2016-nevada-president-trump-vs-clinton"
source("Election2016_EstTable.R")
candidate.DT
# Overlay estimates with polling data
source("Election2016_Polls.R")
est.plotly
#source("Election2016_Est.R")
# Polling data
polls.plotly
schedule.state <- "NV"
source("Election2016_ScheduleTable.R")
schedule.DT
Present Polling Estimate for New Hampshire on October 13, 2016
slug <- "2016-new-hampshire-president-trump-vs-clinton"
source("Election2016_EstTable.R")
candidate.DT
# Overlay estimates with polling data
source("Election2016_Polls.R")
est.plotly
#source("Election2016_Est.R")
# Polling data
polls.plotly
schedule.state <- "NH"
source("Election2016_ScheduleTable.R")
schedule.DT
Present Polling Estimate for Virginia on October 13, 2016
slug <- "2016-virginia-president-trump-vs-clinton"
source("Election2016_EstTable.R")
candidate.DT
# Overlay estimates with polling data
source("Election2016_Polls.R")
est.plotly
#source("Election2016_Est.R")
# Polling data
polls.plotly
schedule.state <- "VA"
source("Election2016_ScheduleTable.R")
schedule.DT
Present Polling Estimate for Wisconsin on October 13, 2016
slug <- "2016-wisconsin-president-trump-vs-clinton"
source("Election2016_EstTable.R")
candidate.DT
# Overlay estimates with polling data
source("Election2016_Polls.R")
est.plotly
#source("Election2016_Est.R")
# Polling data
polls.plotly
schedule.state <- "WI"
source("Election2016_ScheduleTable.R")
schedule.DT