Is racial gerrymandering happening in Tennessee?

These maps indicate the percentage of white people in different districts in 2021 and 2022, respectively. The redistricting was completed in 2022, and shows a noticeable difference. I believe that it is quite clear that racial gerrymandering happened through these graphs and maps, but as the supreme court ruled, gerrymandering in the case of political advantage is not illegal.

U.S. House Districts in 2021

U.S. House Districts in 2022

Code:

# Installing and loading required packages

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

library(tidyverse)
library(tidycensus)
library(sf)
library(mapview)
library(leaflet)
library(leafpop)

options(scipen = 999)

# Transmitting API key

census_api_key("2e2a0ce2c78a86d5656ad34469c6cd33e36076b9")

# Specifying target variables

VariableList = 
  c(Estimate_ = "DP05_0037P")

# Fetching ACS codebooks

ProfileTables <- load_variables(2023, "acs5/profile", cache = TRUE)

# Fetching the data

mydata <- get_acs(
  geography = "congressional district",
  state = c("TN"),
  variables = VariableList,
  year = 2021,
  survey = "acs1",
  output = "wide",
  geometry = TRUE)

mydata <- rename(mydata, Area = NAME,
                 Estimate = Estimate_E,
                 Range = Estimate_M)

# Mapping the data

Map2021 <- mapview(
  mydata,
  zcol = "Estimate",
  layer.name = "Pct. White",
  popup = popupTable(
    mydata,
    feature.id = FALSE,
    row.numbers = FALSE,
    zcol = c("Area", "Estimate", "Range")
  )
)

Map2021

# Plotting the data

mygraph <- ggplot(mydata, aes(x = Estimate, y = reorder(Area, Estimate))) + 
  geom_errorbarh(aes(xmin = Estimate - Range, xmax = Estimate + Range)) + 
  geom_point(size = 13, color = "#099d91") + 
  theme_minimal(base_size = 12.5) +
  labs(title = "Estimates by area", 
       subtitle = "Brackets show error margins.", 
       x = "2019-2023 ACS estimate", 
       y = "")

mygraph

# Specifying target variables

VariableList = 
  c(Estimate_ = "DP03_0062")

# Fetching county-level data for all counties in a state

# Fetching the data

mydata <- get_acs(
  geography = "congressional district",
  state = c("TN"),
  variables = VariableList,
  year = 2021,
  survey = "acs1",
  output = "wide",
  geometry = TRUE)

mydata <- rename(mydata, Area = NAME,
                 Estimate = Estimate_E,
                 Range = Estimate_M)

# Mapping data

Map2021 <- mapview(
  mydata,
  zcol = "Estimate",
  layer.name = "Estimate",
  popup = popupTable(
    mydata,
    feature.id = FALSE,
    row.numbers = FALSE,
    zcol = c("Area", "Estimate", "Range")
  )
)

Map2021

# Plotting data

mygraph <- ggplot(mydata, aes(x = Estimate, y = reorder(Area, Estimate))) + 
  geom_errorbarh(aes(xmin = Estimate - Range, xmax = Estimate + Range)) + 
  geom_point(size = 3, color = "#099d91") + 
  theme_minimal(base_size = 12.5) +
  theme(axis.text.y = element_text(size = 3)) +
  labs(title = "Estimates by area", 
       subtitle = "Brackets show error margins.", 
       x = "2019-2023 ACS estimate", 
       y = "")

Map2021

# Installing and loading required packages

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

library(tidyverse)
library(tidycensus)
library(sf)
library(mapview)
library(leaflet)
library(leafpop)

options(scipen = 999)

# Transmitting API key

census_api_key("2e2a0ce2c78a86d5656ad34469c6cd33e36076b9")

# Specifying target variables

VariableList = 
  c(Estimate_ = "DP05_0037P")

# Fetching ACS codebooks

ProfileTables <- load_variables(2022, "acs5/profile", cache = TRUE)

# Fetching the data

mydata <- get_acs(
  geography = "congressional district",
  state = c("TN"),
  variables = VariableList,
  year = 2022,
  survey = "acs1",
  output = "wide",
  geometry = TRUE)

mydata <- rename(mydata, Area = NAME,
                 Estimate = Estimate_E,
                 Range = Estimate_M)

# Mapping the data

Map2022 <- mapview(
  mydata,
  zcol = "Estimate",
  layer.name = "Pct. White",
  popup = popupTable(
    mydata,
    feature.id = FALSE,
    row.numbers = FALSE,
    zcol = c("Area", "Estimate", "Range")
  )
)

Map2022

# Plotting the data

mygraph2022 <- ggplot(mydata, aes(x = Estimate, y = reorder(Area, Estimate))) + 
  geom_errorbarh(aes(xmin = Estimate - Range, xmax = Estimate + Range)) + 
  geom_point(size = 13, color = "#099d91") + 
  theme_minimal(base_size = 12.5) +
  labs(title = "Estimates by area", 
       subtitle = "Brackets show error margins.", 
       x = "2019-2023 ACS estimate", 
       y = "")

mygraph2022

# Specifying target variables

VariableList = 
  c(Estimate_ = "DP03_0062")

# Fetching county-level data for all counties in a state

# Fetching the data

mydata <- get_acs(
  geography = "congressional district",
  state = c("TN"),
  variables = VariableList,
  year = 2022,
  survey = "acs1",
  output = "wide",
  geometry = TRUE)

mydata <- rename(mydata, Area = NAME,
                 Estimate = Estimate_E,
                 Range = Estimate_M)

# Mapping data

Map2022 <- mapview(
  mydata,
  zcol = "Estimate",
  layer.name = "Estimate",
  popup = popupTable(
    mydata,
    feature.id = FALSE,
    row.numbers = FALSE,
    zcol = c("Area", "Estimate", "Range")
  )
)

Map2022

# Plotting data

mygraph2022 <- ggplot(mydata, aes(x = Estimate, y = reorder(Area, Estimate))) + 
  geom_errorbarh(aes(xmin = Estimate - Range, xmax = Estimate + Range)) + 
  geom_point(size = 3, color = "#099d91") + 
  theme_minimal(base_size = 12.5) +
  theme(axis.text.y = element_text(size = 3)) +
  labs(title = "Estimates by area", 
       subtitle = "Brackets show error margins.", 
       x = "2019-2023 ACS estimate", 
       y = "")

Map2022

if (!require("tidyverse")) install.packages("tidyverse")
if (!require("RColorBrewer")) install.packages("RColorBrewer")

library(tidyverse)
library(RColorBrewer)


# Load the data
Davidson2024 <- read.csv("https://github.com/drkblake/Data/raw/refs/heads/main/Davidson2024.csv")

# Load necessary library


if (!require("tidyverse")) install.packages("tidyverse")
if (!require("RColorBrewer")) install.packages("RColorBrewer")

library(tidyverse)
library(RColorBrewer)

library(ggplot2)

# Load the dataset
Davidson2024 <- read.csv("https://github.com/drkblake/Data/raw/refs/heads/main/Davidson2024.csv")


# Plot
ggplot(Davidson2024, aes(x = Pct_Nonwhite, y = Pct_Harris, color = Winner)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE) +
  labs(
    x = "Pct. Minority",
    y = "Pct. Harris",
    color = "Winner",
    title = "Support for Harris, by percent minority, 2024",
    caption = "Source: U.S. Census Bureau"
  ) +
  scale_color_brewer(palette = "Dark2")