5.1 Category 3 Variable 1: Native-born U.S citizen
[Map]
<- paste0("<b>",countyGIS_map$name," (",countyGIS_map$FIPS,")</b>",
popupLabels_nativeborn "<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 Native-born: ", format(round(countyGIS_map$pct_us_born, 2),big.mark=",", trim=TRUE),
"%</font>"
%>%
) lapply(htmltools::HTML)
<- colorNumeric(
pal palette = colorRampPalette(c('blue', 'white'))(length(countyGIS_map$pct_us_born)),
domain = countyGIS_map$pct_us_born, 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_us_born), fillOpacity = 1, smoothFactor = 0.5,
label = popupLabels_nativeborn,
labelOptions = labelOptions(direction = "auto")) %>%
addPolygons(data = stateGIS,fill = FALSE,color="black",weight = 1) %>%
addLegend(pal = pal,values = ~countyGIS_map$pct_us_born, opacity = 0.7, title = "% Native-born",position = "bottomright")
[Scatter plot]
ggplot(countyGIS_stat, aes(x=pct_us_born, y=pctGOP)) + geom_point(aes(alpha = pct_white, shape = ".")) + geom_smooth(method = "lm", se=FALSE)
## `geom_smooth()` using formula 'y ~ x'
[Regression]
# Estimate regression model
<- lm(pctGOP ~ pct_us_born, data=countyGIS_stat)
pct_us_born_reg
# Display model results
pander(summary(pct_us_born_reg))
Estimate | Std. Error | t value | Pr(>|t|) | |
---|---|---|---|---|
(Intercept) | -0.3682 | 0.04197 | -8.773 | 2.819e-18 |
pct_us_born | 0.01092 | 0.0004432 | 24.63 | 1.98e-122 |
Observations | Residual Std. Error | \(R^2\) | Adjusted \(R^2\) |
---|---|---|---|
3083 | 0.1474 | 0.1645 | 0.1642 |