DataCamp Analyzing Election and Polling Data in R
The 2016 US Presidential Election
ANALYZING ELECTION AND POLLING DATA IN R
- G. Elliott Morris
The 2016 US Presidential Election G. Elliott Morris Data - - PowerPoint PPT Presentation
DataCamp Analyzing Election and Polling Data in R ANALYZING ELECTION AND POLLING DATA IN R The 2016 US Presidential Election G. Elliott Morris Data Journalist DataCamp Analyzing Election and Polling Data in R Understanding presidential
DataCamp Analyzing Election and Polling Data in R
ANALYZING ELECTION AND POLLING DATA IN R
DataCamp Analyzing Election and Polling Data in R
DataCamp Analyzing Election and Polling Data in R
DataCamp Analyzing Election and Polling Data in R
DataCamp Analyzing Election and Polling Data in R
DataCamp Analyzing Election and Polling Data in R
choroplethr package
DataCamp Analyzing Election and Polling Data in R
left_join(df_county_demographics, uspres_county, by = "county.fips") county.fips total_population percent_white percent_black percent_asian 1 1001 54907 76 18 1 2 1003 187114 83 9 1 3 1005 27321 46 46 0 4 1007 22754 75 22 0 5 1009 57623 88 1 0 6 1011 10746 22 71 0 percent_hispanic per_capita_income median_rent median_age county.name 1 2 24571 668 37.5 autauga 2 4 26766 693 41.5 baldwin 3 5 16829 382 38.3 barbour 4 2 17427 351 39.4 bibb 5 8 20730 403 39.6 blount 6 6 18628 276 39.6 bullock state.name county.total.count D O R Dem.pct 1 alabama 24973 5936 865 18172 0.23769671 2 alabama 95215 18458 3874 72883 0.19385601 3 alabama 10469 4871 144 5454 0.46527844 4 alabama 8819 1874 207 6738 0.21249575 5 alabama 25588 2156 573 22859 0.08425825 6 alabama 4710 3530 40 1140 0.74946921
DataCamp Analyzing Election and Polling Data in R
library(ggplot2) ggplot(county_merged, aes(x=percent_white,y=Dem.pct)) + geom_point()
DataCamp Analyzing Election and Polling Data in R
DataCamp Analyzing Election and Polling Data in R
library(ggplot2) ggplot(county_merged, aes(x=percent_white,y=Dem.pct)) + geom_point() ggplot(county_merged, aes(x=percent_white,y=Dem.pct)) + geom_point() + geom_smooth(method="lm")
DataCamp Analyzing Election and Polling Data in R
DataCamp Analyzing Election and Polling Data in R
ANALYZING ELECTION AND POLLING DATA IN R
DataCamp Analyzing Election and Polling Data in R
ANALYZING ELECTION AND POLLING DATA IN R
DataCamp Analyzing Election and Polling Data in R
DataCamp Analyzing Election and Polling Data in R
DataCamp Analyzing Election and Polling Data in R
choroplethr: fast visualization, low customizability, comes with data ggplot + geom_sf(): fast, customizability, need for data leaflet: interactive, customizable, steep learning curve, need for data
DataCamp Analyzing Election and Polling Data in R
DataCamp Analyzing Election and Polling Data in R
DataCamp Analyzing Election and Polling Data in R
DataCamp Analyzing Election and Polling Data in R
library(choroplethr) county_map <- county_merged %>% dplyr::rename("region" = county.fips, "value" = Dem.pct) county_choropleth(county_map)
DataCamp Analyzing Election and Polling Data in R
DataCamp Analyzing Election and Polling Data in R
ANALYZING ELECTION AND POLLING DATA IN R
DataCamp Analyzing Election and Polling Data in R
ANALYZING ELECTION AND POLLING DATA IN R
DataCamp Analyzing Election and Polling Data in R
DataCamp Analyzing Election and Polling Data in R
DataCamp Analyzing Election and Polling Data in R
fit <- lm(Dem.pct ~ percent_white, data=county_merged) summary(fit) Call: lm(formula = Dem.pct ~ percent_white, data = county_merged) Residuals: Min 1Q Median 3Q Max
Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 0.6719046 0.0090408 74.32 <2e-16 *** percent_white -0.0045684 0.0001123 -40.68 <2e-16 ***
DataCamp Analyzing Election and Polling Data in R
summary(fit) Call: lm(formula = Dem.pct ~ percent_white, data = county_merged) Residuals: Min 1Q Median 3Q Max
Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 0.6719046 0.0090408 74.32 <2e-16 *** percent_white -0.0045684 0.0001123 -40.68 <2e-16 ***
Residual standard error: 0.1227 on 3097 degrees of freedom (44 observations deleted due to missingness) Multiple R-squared: 0.3482, Adjusted R-squared: 0.348 F-statistic: 1655 on 1 and 3097 DF, p-value: < 2.2e-16
DataCamp Analyzing Election and Polling Data in R
ANALYZING ELECTION AND POLLING DATA IN R
DataCamp Analyzing Election and Polling Data in R
ANALYZING ELECTION AND POLLING DATA IN R
DataCamp Analyzing Election and Polling Data in R
DataCamp Analyzing Election and Polling Data in R
DataCamp Analyzing Election and Polling Data in R
head(brexit_polls) Date Remain Leave RemainLead 1 6/23/16 52 48 4 2 6/22/16 55 45 10 3 6/22/16 51 49 2 4 6/22/16 49 46 3 5 6/22/16 44 45 -1 6 6/22/16 54 46 8 7 6/22/16 48 42 6 8 6/22/16 41 43 -2 9 6/20/16 45 44 1 10 6/19/16 42 44 -2
DataCamp Analyzing Election and Polling Data in R
DataCamp Analyzing Election and Polling Data in R
ggplot(brexit_polls, aes(x = mdy(Date), y = Remain - Leave)) + geom_point() + geom_smooth(method = 'loess')
DataCamp Analyzing Election and Polling Data in R
DataCamp Analyzing Election and Polling Data in R
DataCamp Analyzing Election and Polling Data in R
ANALYZING ELECTION AND POLLING DATA IN R