3.2 Category 1 Variable 2: Asian Population
[Map]
<- paste0("<b>",countyGIS_map$name," (",countyGIS_map$FIPS,")</b>",
popupLabels_Asian "<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 Asian: ", format(round(countyGIS_map$pct_asian, 2),big.mark=",", trim=TRUE),
"%</font>"
%>%
) lapply(htmltools::HTML)
<- colorNumeric(
pal2 palette = colorRampPalette(c('yellow', 'white'))(length(countyGIS_map$pct_asian)),
domain = countyGIS_map$pct_asian, 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_asian), fillOpacity = 1, smoothFactor = 0.5,
label = popupLabels_Asian,
labelOptions = labelOptions(direction = "auto")) %>%
addPolygons(data = stateGIS,fill = FALSE,color="black",weight = 1) %>%
addLegend(pal = pal2,values = ~countyGIS_map$pct_asian, opacity = 0.7, title = "% Asian",position = "bottomright")
[Scatter plot]
<- ggplot(countyGIS_stat, aes(pct_asian, pctGOP)) +
pct_asian_vs_pctGOP geom_point(aes(alpha = pct_asian, shape = ".")) +
geom_smooth(method = "lm", se = FALSE)
pct_asian_vs_pctGOP
[Regression]
# Estimate regression model
<- lm(pctGOP ~ pct_asian, data=countyGIS_stat)
pct_asian_reg
# Display model results
pander(summary(pct_asian_reg))
Estimate | Std. Error | t value | Pr(>|t|) | |
---|---|---|---|---|
(Intercept) | 0.7007 | 0.002915 | 240.4 | 0 |
pct_asian | -0.0278 | 0.000994 | -27.97 | 1.431e-153 |
Observations | Residual Std. Error | \(R^2\) | Adjusted \(R^2\) |
---|---|---|---|
3083 | 0.144 | 0.2025 | 0.2022 |