library(ggthemes)
## Warning: package 'ggthemes' was built under R version 3.2.5
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.2.5
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.2.5
library(ggmap)
## Warning: package 'ggmap' was built under R version 3.2.5
library(maps)
## Warning: package 'maps' was built under R version 3.2.5
library(mapdata)
## Warning: package 'mapdata' was built under R version 3.2.5
library(ggthemes)
library(dplyr)
library(ggplot2)
library(ggmap)
library(maps)
library(mapdata)
polls.16 <- read.csv("http://projects.fivethirtyeight.com/general-model/president_general_polls_2016.csv")
polls.16 %>% head()
## cycle branch type matchup forecastdate
## 1 2016 President polls-plus Clinton vs. Trump vs. Johnson 11/8/16
## 2 2016 President polls-plus Clinton vs. Trump vs. Johnson 11/8/16
## 3 2016 President polls-plus Clinton vs. Trump vs. Johnson 11/8/16
## 4 2016 President polls-plus Clinton vs. Trump vs. Johnson 11/8/16
## 5 2016 President polls-plus Clinton vs. Trump vs. Johnson 11/8/16
## 6 2016 President polls-plus Clinton vs. Trump vs. Johnson 11/8/16
## state startdate enddate
## 1 U.S. 11/3/2016 11/6/2016
## 2 U.S. 11/1/2016 11/7/2016
## 3 U.S. 11/2/2016 11/6/2016
## 4 U.S. 11/4/2016 11/7/2016
## 5 U.S. 11/3/2016 11/6/2016
## 6 U.S. 11/3/2016 11/6/2016
## pollster grade
## 1 ABC News/Washington Post A+
## 2 Google Consumer Surveys B
## 3 Ipsos A-
## 4 YouGov B
## 5 Gravis Marketing B-
## 6 Fox News/Anderson Robbins Research/Shaw & Company Research A
## samplesize population poll_wt rawpoll_clinton rawpoll_trump
## 1 2220 lv 8.720654 47.00 43.00
## 2 26574 lv 7.628472 38.03 35.69
## 3 2195 lv 6.424334 42.00 39.00
## 4 3677 lv 6.087135 45.00 41.00
## 5 16639 rv 5.316449 47.00 43.00
## 6 1295 lv 5.218141 48.00 44.00
## rawpoll_johnson rawpoll_mcmullin adjpoll_clinton adjpoll_trump
## 1 4.00 NA 45.20163 41.72430
## 2 5.46 NA 43.34557 41.21439
## 3 6.00 NA 42.02638 38.81620
## 4 5.00 NA 45.65676 40.92004
## 5 3.00 NA 46.84089 42.33184
## 6 3.00 NA 49.02208 43.95631
## adjpoll_johnson adjpoll_mcmullin multiversions
## 1 4.626221 NA
## 2 5.175792 NA
## 3 6.844734 NA
## 4 6.069454 NA
## 5 3.726098 NA
## 6 3.057876 NA
## url
## 1 https://www.washingtonpost.com/news/the-fix/wp/2016/11/07/post-abc-tracking-poll-clinton-47-trump-43-on-election-eve/
## 2 https://datastudio.google.com/u/0/#/org//reporting/0B29GVb5ISrT0TGk1TW5tVF9Ed2M/page/GsS
## 3 http://projects.fivethirtyeight.com/polls/20161108_National_2.pdf
## 4 https://d25d2506sfb94s.cloudfront.net/cumulus_uploads/document/l37rosbwjp/econTabReport_lv.pdf
## 5 http://www.gravispolls.com/2016/11/final-national-poll-2016-gravis.html?m=1
## 6 http://www.foxnews.com/politics/2016/11/07/fox-news-poll-results-11716.html
## poll_id question_id createddate timestamp
## 1 48630 76192 11/7/16 09:35:33 8 Nov 2016
## 2 48847 76443 11/7/16 09:35:33 8 Nov 2016
## 3 48922 76636 11/8/16 09:35:33 8 Nov 2016
## 4 48687 76262 11/7/16 09:35:33 8 Nov 2016
## 5 48848 76444 11/7/16 09:35:33 8 Nov 2016
## 6 48619 76163 11/7/16 09:35:33 8 Nov 2016
states <- map_data("state")
dim(states)
## [1] 15537 6
states %>% head(3)
## long lat group order region subregion
## 1 -87.46201 30.38968 1 1 alabama <NA>
## 2 -87.48493 30.37249 1 2 alabama <NA>
## 3 -87.52503 30.37249 1 3 alabama <NA>
polls.16.ave <- polls.16 %>%
mutate(region = tolower(state)) %>%
group_by(region) %>%
summarise(clin.vote.ave = mean(adjpoll_clinton))
states.clinton <- inner_join(polls.16.ave, states, by = "region")
polls.16.stry <- polls.16 %>%
filter(state=="Florida",pollster=="Google Consumer Surveys",type=="polls-only") %>%
arrange(-adjpoll_clinton)
p <- ggplot(data = polls.16.stry, aes(x = startdate, y = adjpoll_clinton))+
geom_point()+
theme(axis.text.x=element_text(angle=45,hjust=1))
p
