Early voting in Rutherford County

To date, 27 percent of all registered voters in Rutherford County have cast their ballot for the November 5 election.

The graph below breaks down the vote totals per day, according to data from the Rutherford County Election Commission.

The map below breaks down total voter turnout to date by precinct. For more details, click on a precinct.

The full code script is below:

download.file("https://github.com/drkblake/Data/raw/refs/heads/main/DailyEVFiles.zip",
              "DailyEVFiles.zip")
unzip("DailyEVFiles.zip")

if (!require("tidyverse"))
  install.packages("tidyverse")
if (!require("foreign"))
  install.packages("foreign")
if (!require("sf"))
  install.packages("sf")
if (!require("scales"))
  install.packages("scales")
if (!require("mapview"))
  install.packages("mapview")
if (!require("leaflet"))
  install.packages("leaflet")
if (!require("leaflet.extras2"))
  install.packages("leaflet.extras2")

library(tidyverse)
library(foreign)
library(sf)
library(scales)
library(mapview)
library(leaflet)
library(leafpop)

# Read the first data file and use it to create
# an "AllData" dataframe.

AddData <- read.dbf("10162024.dbf")
AllData <- AddData

# Add each subsequent day's file name to this list,
# then run

datafiles <- c("10172024.dbf",
               "10182024.dbf",
               "10192024.dbf",
               "10212024.dbf",
               "10222024.dbf",
               "10232024.dbf")

# This "for loop" adds each listed datafile
# to the AllData dataframe

for (x in datafiles) {
  AddData <- read.dbf(x, as.is = FALSE)
  AllData <- rbind(AllData, AddData)
}

# Save AllData file as .csv
write_csv(AllData,"EarlyVoterData2024.csv")

TotalVotes <- nrow(AllData)
PctVotes <- round((TotalVotes / 224746)*100, digits = 0)

### Make a chart showing vote totals by day ###

# Aggregate data by day
# and do some formatting

VotesByDay <- AllData %>% 
  group_by(VOTEDDATE) %>% 
  summarize(Votes = n()) %>% 
  rename(Date = VOTEDDATE) %>% 
  mutate(Date = (str_remove(Date,"2024-")))

# Make the chart

chart = ggplot(data = VotesByDay,
               aes(x = Date,
                   y = Votes))+
  geom_bar(stat="identity", fill = "#41B3A2") +
  geom_text(aes(label=comma(Votes)),
            vjust=1.6,
            color="black",
            size=3.5)+
  theme(
    axis.title.x = element_blank(),
    axis.ticks.y = element_blank(),
    axis.title.y = element_blank(),
    axis.text.y = element_blank(),
    panel.background = element_blank())

# Show the chart

chart

### Make a precinct-level map of early voting turnout ***

# Aggregate early voting data by precinct

PrecinctData <- AllData %>% 
  group_by(PCT_NBR) %>% 
  summarize(Votes = n()) %>% 
  rename(Precinct = PCT_NBR)

# Download and unzip a precinct map to pair with the vote data

download.file("https://github.com/drkblake/Data/raw/main/Voting_Precincts_5_31_24.zip","TNVotingPrecincts.zip")

unzip("TNVotingPrecincts.zip")

# Read the unzipped data into an All_Precincts dataframe

All_Precincts <- read_sf("Voting_Precincts_5_31_24.shp")

# Filter for RuCo precincts, 
# strip dash from precinct numbers,
# and do some renaming

County_Precincts <- All_Precincts %>%
  filter(COUNTY == 149) %>%
  rename(Precinct = NEWVOTINGP) %>% 
  mutate(Precinct = (str_remove(Precinct,"-")))

# Use left_join() function to join the data and map file
# using the "Precinct" variable as the joining key

MapData <-  left_join(PrecinctData, County_Precincts, by = "Precinct")

# Use left_join() again, this time to add
# voter registration totals per precinct
# This file was in the .zip file along with
# the daily .dbf files

RegData <- read_csv("RegVotersRuCo.csv") %>% 
  mutate(Precinct = as.character(Precinct))

MapData <- left_join(MapData, RegData, by = "Precinct")

# Calculate and add Percent column
# Then select columns to keep
# and put them in a MapData dataframe

MapData <- MapData %>% 
  mutate(Percent = round((Votes/RegVoters)*100), digits = 0) %>%
  rename(Voters = RegVoters) %>% 
  select(Precinct, Votes, Voters, Percent, geometry)

# Make a mappable MapData_sf file out of MapData

MapData_sf <- st_as_sf(MapData)

# Make the map

Map <- mapview(
  MapData_sf,
  zcol = "Percent",
  layer.name = "Pct. early voted",
  popup = popupTable(
    MapData_sf,
    feature.id = FALSE,
    row.numbers = FALSE,
    zcol = c(
      "Precinct",
      "Votes",
      "Voters",
      "Percent"
    )
  )
)

# Show the map

Map

# Calculate some additional voting stats

MinTurnout <- min(MapData$Percent)
MaxTurnout <- max(MapData$Percent)
MedianTurnout <- median(MapData$Percent)
MeanTurnout <- mean(MapData$Percent)