5.2 Category 2 Variable 2: Naturalized U.S citizen
[Map]
<- paste0("<b>",countyGIS_map$name," (",countyGIS_map$FIPS,")</b>",
popupLabels_naturalized "<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 Naturalized: ", format(round(countyGIS_map$pct_us_naturalized, 2),big.mark=",", trim=TRUE),
"%</font>"
%>%
) lapply(htmltools::HTML)
<- colorNumeric(
pal2 palette = colorRampPalette(c('red', 'white'))(length(countyGIS_map$pct_us_naturalized)),
domain = countyGIS_map$pct_us_naturalized, reverse=TRUE)
leaflet(countyGIS_map, options = leafletOptions(crsClass = "L.CRS.EPSG3857"), width="100%") %>%
addPolygons(weight = 0.5, color = "gray", opacity = 0.7,
fillColor = ~pal2(pct_us_naturalized), fillOpacity = 1, smoothFactor = 0.5,
label = popupLabels_naturalized,
labelOptions = labelOptions(direction = "auto")) %>%
addPolygons(data = stateGIS,fill = FALSE,color="black",weight = 1) %>%
addLegend(pal = pal2,values = ~countyGIS_map$pct_us_naturalized, opacity = 0.7, title = "% Naturalized",position = "bottomright")
[Scatter plot]
ggplot(countyGIS_stat, aes(pct_us_naturalized, pctGOP)) + geom_point(aes(alpha = pct_white, shape = ".")) + geom_smooth(method = "lm", se = FALSE)
[Regression]
# Estimate regression model
<- lm(pctGOP ~ pct_us_naturalized, data=countyGIS_stat)
pct_us_naturalized_reg
# Display model results
pander(summary(pct_us_naturalized_reg))
Estimate | Std. Error | t value | Pr(>|t|) | |
---|---|---|---|---|
(Intercept) | 0.7199 | 0.00326 | 220.9 | 0 |
pct_us_naturalized | -0.02799 | 0.0009847 | -28.43 | 4.704e-158 |
Observations | Residual Std. Error | \(R^2\) | Adjusted \(R^2\) |
---|---|---|---|
3083 | 0.1435 | 0.2078 | 0.2075 |