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.


Days until Election Day: 26


National Polling Estimate

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


National Polling Data

National Estimates

The line represents HuffPost Pollster’s estimate for overall support based on polling data.

source("Election2016_Polls.R")

est.plotly 

National Polls

National support for the two main US presidential candidates according to various polling organizations.

# Comes from `Election2016_Polls.R` script.

polls.plotly


Electoral Map

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


Campaign Stops

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.

Today

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

Yesterday

# 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

Last Three Days

# 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

Last 7 Days

# 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

Last 30 Days

# 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

Since July 31, 2016

# 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

Campaign Focus

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).


Battleground States

There are roughly eleven swing states.

A source within the Trump campaign identified four must-win states: Ohio, Pennsylvania, Florida, and North Carolina.


Florida

Present Polling Estimate for Florida on October 13, 2016

slug <- "2016-florida-presidential-general-election-trump-vs-clinton"

source("Election2016_EstTable.R")

candidate.DT


Florida Polling Data

Florida Estimates
# Overlay estimates with polling data
source("Election2016_Polls.R")
est.plotly
Florida Polls
#source("Election2016_Est.R")

# Polling data
polls.plotly


Campaign Visits to Florida

schedule.state <- "FL"

source("Election2016_ScheduleTable.R")

schedule.DT

North Carolina

Present Polling Estimate for North Carolina on October 13, 2016

slug <- "2016-north-carolina-president-trump-vs-clinton"

source("Election2016_EstTable.R")

candidate.DT


North Carolina Polling Data

North Carolina Estimates
# Overlay estimates with polling data
source("Election2016_Polls.R")
est.plotly
North Carolina Polls
#source("Election2016_Est.R")

# Polling data
polls.plotly


Campaign Visits to North Carolina

schedule.state <- "NC"

source("Election2016_ScheduleTable.R")

schedule.DT

Ohio

Present Polling Estimate for Ohio on October 13, 2016

slug <- "2016-ohio-president-trump-vs-clinton"

source("Election2016_EstTable.R")

candidate.DT


Ohio Polling Data

Ohio Estimates
# Overlay estimates with polling data
source("Election2016_Polls.R")
est.plotly
Ohio Polls
#source("Election2016_Est.R")

# Polling data
polls.plotly


Campaign Visits to Ohio

schedule.state <- "OH"

source("Election2016_ScheduleTable.R")

schedule.DT

Pennsylvania

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


Pennsylvania Polling Data

Pennsylvania Estimates
# Overlay estimates with polling data
source("Election2016_Polls.R")
est.plotly
Pennsylvania Polls
#source("Election2016_Est.R")

# Polling data
polls.plotly


Campaign Visits to Pennsylvania

schedule.state <- "PA"

source("Election2016_ScheduleTable.R")

schedule.DT

Other

Colorado

Present Polling Estimate for Colorado on October 13, 2016

slug <- "2016-colorado-president-trump-vs-clinton"

source("Election2016_EstTable.R")

candidate.DT


Colorado Polling Data
Colorado Estimates
# Overlay estimates with polling data
source("Election2016_Polls.R")
est.plotly
Colorado Polls
#source("Election2016_Est.R")

# Polling data
polls.plotly


Campaign Visits to Colorado
schedule.state <- "CO"

source("Election2016_ScheduleTable.R")

schedule.DT

Iowa

Present Polling Estimate for Iowa on October 13, 2016

slug <- "2016-iowa-president-trump-vs-clinton"

source("Election2016_EstTable.R")

candidate.DT


Iowa Polling Data
Iowa Estimates
source("Election2016_Polls.R")
# Overlay estimates with polling data
est.plotly
Iowa Polls
#source("Election2016_Est.R")

# Polling data
polls.plotly


Campaign Visits to Iowa
schedule.state <- "IA"

source("Election2016_ScheduleTable.R")

schedule.DT

Michigan

Present Polling Estimate for Michigan on October 13, 2016

slug <- "2016-michigan-president-trump-vs-clinton"

source("Election2016_EstTable.R")

candidate.DT


Michigan Polling Data
Michigan Estimates
# Overlay estimates with polling data
source("Election2016_Polls.R")
est.plotly
Michigan Polls
#source("Election2016_Est.R")

# Polling data
polls.plotly


Campaign Visits to Michigan
schedule.state <- "MI"

source("Election2016_ScheduleTable.R")

schedule.DT

Nevada

Present Polling Estimate for Nevada on October 13, 2016

slug <- "2016-nevada-president-trump-vs-clinton"

source("Election2016_EstTable.R")

candidate.DT


Nevada Polling Data
Nevada Estimates
# Overlay estimates with polling data
source("Election2016_Polls.R")
est.plotly
Nevada Polls
#source("Election2016_Est.R")

# Polling data
polls.plotly


Campaign Visits to Nevada
schedule.state <- "NV"

source("Election2016_ScheduleTable.R")

schedule.DT

New Hampshire

Present Polling Estimate for New Hampshire on October 13, 2016

slug <- "2016-new-hampshire-president-trump-vs-clinton"

source("Election2016_EstTable.R")

candidate.DT


New Hampshire Polling Data
New Hampshire Estimates
# Overlay estimates with polling data
source("Election2016_Polls.R")
est.plotly
New Hampshire Polls
#source("Election2016_Est.R")

# Polling data
polls.plotly


Campaign Visits to New Hampshire
schedule.state <- "NH"

source("Election2016_ScheduleTable.R")

schedule.DT

Virginia

Present Polling Estimate for Virginia on October 13, 2016

slug <- "2016-virginia-president-trump-vs-clinton"

source("Election2016_EstTable.R")

candidate.DT


Virginia Polling Data
Virginia Estimates
# Overlay estimates with polling data
source("Election2016_Polls.R")
est.plotly
Virginia Polls
#source("Election2016_Est.R")

# Polling data
polls.plotly


Campaign Visits to Virginia
schedule.state <- "VA"

source("Election2016_ScheduleTable.R")

schedule.DT

Wisconsin

Present Polling Estimate for Wisconsin on October 13, 2016

slug <- "2016-wisconsin-president-trump-vs-clinton"

source("Election2016_EstTable.R")

candidate.DT


Wisconsin Polling Data
Wisconsin Estimates
# Overlay estimates with polling data
source("Election2016_Polls.R")
est.plotly
Wisconsin Polls
#source("Election2016_Est.R")

# Polling data
polls.plotly


Campaign Visits to Wisconsin
schedule.state <- "WI"

source("Election2016_ScheduleTable.R")

schedule.DT