5.1 Category 3 Variable 1: Native-born U.S citizen

[Map]

popupLabels_nativeborn <- paste0("<b>",countyGIS_map$name," (",countyGIS_map$FIPS,")</b>",
                    "<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)
pal <- colorNumeric(
  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
pct_us_born_reg <- lm(pctGOP ~ pct_us_born, data=countyGIS_stat)

# 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
Fitting linear model: pctGOP ~ pct_us_born
Observations Residual Std. Error \(R^2\) Adjusted \(R^2\)
3083 0.1474 0.1645 0.1642