library(sf)
library(dplyr)
library(ggplot2)
Loading in the election Data. This analysis focuses on the 2018 US Senate Election in Texas
tx_data <- st_make_valid(st_read("C:/Users/spock/Downloads/tx_2018/tx_2018.shp"))
Adding in columns for vote percentage
tx_data <- tx_data |>
mutate(
cruz_pct = G18USSRCRU/(G18USSRCRU + G18USSDORO + G18USSLDIK),
beto_pct = G18USSDORO/(G18USSRCRU + G18USSDORO + G18USSLDIK)
)
Choosing Counties for analysis
counties <- c(26,29,30)
tx_counties <- tx_data |>
filter(CNTY %in% counties)
ggplot() +
geom_sf(data = tx_counties, aes(fill = cruz_pct), color = "black", alpha = 0.7) +
theme_minimal() +
scale_fill_gradient2(low = "blue", mid = "white", high = "red",
midpoint = 0.5,
limits = c(0, 1),
na.value = "grey50",
name = "2018 Cruz %") +
labs(title = "Cruz Vote Share in Burleson, Calhoun, and Callahan Counties")