The 2024 presidential election

This interactive map shows precinct-level results from the 2024 U.S. presidential election in Tennessee, along with borders for the state’s nine U.S. House districts after the 2022 redistricting. Redder shades indicate higher Republican margins, while bluer shades indicate higher Democratic margins. Data and precinct boundaries come from The New York Times and match the Tennessee portion of the Times’ Extremely Detailed Map of the 2024 Election.

Click or tap a precinct for details. Zoom or pan to explore specific areas. Click or tap the map layer icon in the lower-left corner to switch base maps.


R code:

This R code produced the map shown above.

# ============================================================
# 0. INSTALL AND LOAD REQUIRED PACKAGES
# ============================================================

if (!require("tidyverse")) install.packages("tidyverse")
if (!require("tidycensus")) install.packages("tidycensus")
if (!require("sf")) install.packages("sf")
if (!require("leaflet")) install.packages("leaflet")
if (!require("leaflet.extras2")) install.packages("leaflet.extras2")

library(tidyverse)
library(tidycensus)
library(sf)
library(leaflet)
library(leaflet.extras2)

# ============================================================
# 1. LOAD PRECINCT-LEVEL 2024 RESULTS (GEOJSON)
# ============================================================

precincts <- st_read(
  "TN-precincts-with-results.geojson",
  quiet = TRUE
) %>%
  st_transform(4326)

precincts <- precincts %>%
  mutate(
    pct_rep_lead = -pct_dem_lead
  )

# ============================================================
# 2. DISABLE S2 + SIMPLIFY GEOMETRY (CRITICAL FIX)
# ============================================================

sf::sf_use_s2(FALSE)

precincts_simplified <- st_simplify(
  precincts,
  dTolerance = 0.0002,        # ~20–25 meters
  preserveTopology = TRUE
)

sf::sf_use_s2(TRUE)

# ============================================================
# 3. LOAD LATEST CONGRESSIONAL DISTRICTS (POST‑2022)
# ============================================================

congressional_districts <- get_acs(
  geography  = "congressional district",
  state      = "TN",
  variables  = "B01001_001",
  year       = 2023,
  survey     = "acs5",
  geometry   = TRUE
) %>%
  st_transform(4326)

# ============================================================
# 4. COLOR PALETTE (REPUBLICAN MARGIN)
# ============================================================

pal <- colorNumeric(
  palette  = "RdBu",
  domain   = precincts_simplified$pct_rep_lead,
  reverse  = TRUE,             # Red = GOP, Blue = Dem
  na.color = "transparent"
)

# ============================================================
# 5. LEAFLET MAP
# ============================================================

TN_Precinct_2024_Map <- leaflet(precincts_simplified) %>%
  addProviderTiles("CartoDB.Positron", group = "Positron (Light)") %>%
  addProviderTiles("Esri.WorldStreetMap", group = "ESRI Streets") %>%
  addProviderTiles("Esri.WorldImagery", group = "ESRI Satellite") %>%
  
  addPolygons(
    fillColor   = ~pal(pct_rep_lead),
    fillOpacity = 0.75,
    color       = "#555555",
    weight      = 0.25,
    popup = ~paste0(
      "<b>Precinct GEOID:</b> ", GEOID, "<br><br>",
      "<b>Dem votes:</b> ", scales::comma(votes_dem), "<br>",
      "<b>Republican votes:</b> ", scales::comma(votes_rep), "<br>",
      "<b>Total votes:</b> ", scales::comma(votes_total), "<br><br>",
      "<b>Republican margin:</b> ",
      round(100 * pct_rep_lead, 1), " pts"
    ),
    group = "2024 Precinct Results"
  ) %>%
  
  addPolylines(
    data    = congressional_districts,
    color   = "black",
    weight  = 2,
    opacity = 0.9,
    group   = "Congressional Districts (Post‑2022)"
  ) %>%
  
  addLegend(
    pal = pal,
    values = ~pct_rep_lead,
    title = "Republican margin<br>(percentage points)",
    position = "topright",
    labFormat = labelFormat(
      transform = function(x) x * 100,
      suffix = "%"
    )
  ) %>%
  
  addLayersControl(
    baseGroups = c(
      "Positron (Light)",
      "ESRI Streets",
      "ESRI Satellite"
    ),
    overlayGroups = c(
      "2024 Precinct Results",
      "Congressional Districts (Post‑2022)"
    ),
    options = layersControlOptions(
      collapsed = TRUE,
      position  = "bottomleft"
    )
  )

TN_Precinct_2024_Map