4.1 Category 2 Variable 1: White Adults
[map]
<- paste0("<b>",countyGIS_map$name," (",countyGIS_map$FIPS,")</b>",
popupLabels_WhiteAge "<br><font color='",countyGIS_map$FontColorWinner,"'>",countyGIS_map$winner,
": ",
format(countyGIS_map$pctWinner*100,digits=4, trim=TRUE),
"%</font>",
"<br>Total votes: ", format(countyGIS_map$totalVotes,big.mark=",", trim=TRUE),
"<br>Percent White Age: ", format(round(countyGIS_map$pct_whiteage, 2),big.mark=",", trim=TRUE),
"%</font>"
%>%
) lapply(htmltools::HTML)
<- colorNumeric(
pal palette = colorRampPalette(c('Pink', 'white'))(length(countyGIS_map$pct_whiteage)),
domain = countyGIS_map$pct_whiteage, reverse=TRUE)
leaflet(countyGIS_map, options = leafletOptions(crsClass = "L.CRS.EPSG3857"), width="100%") %>%
addPolygons(weight = 0.5, color = "gray", opacity = 0.7,
fillColor = ~pal(pct_whiteage), fillOpacity = 1, smoothFactor = 0.5,
label = popupLabels_WhiteAge,
labelOptions = labelOptions(direction = "auto")) %>%
addPolygons(data = stateGIS,fill = FALSE,color="black",weight = 1) %>%
addLegend(pal = pal,values = ~countyGIS_map$pct_whiteage, opacity = 0.7, title = "% White Age",position = "bottomright")
[Scatter plot]
<- ggplot(countyGIS_stat, aes(pct_whiteage, pctGOP)) +
pct_whiteage_vs_pctGOP geom_point(aes(alpha = pct_whiteage, shape = ".")) +
geom_smooth(method = "lm", se = FALSE)
pct_whiteage_vs_pctGOP
[Regression]
# Estimate regression model
<- lm(pctGOP ~ pct_whiteage, data=countyGIS_stat)
pct_whiteage_reg
# Display model results
pander(summary(pct_whiteage_reg))
Estimate | Std. Error | t value | Pr(>|t|) | |
---|---|---|---|---|
(Intercept) | 0.2514 | 0.01277 | 19.68 | 2.475e-81 |
pct_whiteage | 0.006331 | 0.0001924 | 32.91 | 8.709e-204 |
Observations | Residual Std. Error | \(R^2\) | Adjusted \(R^2\) |
---|---|---|---|
3083 | 0.1387 | 0.2601 | 0.2598 |