Population_v2
County CurrentPop EarlierPop Region Change Percent_change Square_Miles Density Density_Category
Davidson 715388 598184 Davidson 117204 0.1959330 504 1419.42063 High Density
Rutherford 360646 292425 Doughnut 68221 0.2332940 620 581.68710 High Density
Williamson 260351 208242 Doughnut 52109 0.2502329 583 446.57118 Medium Density
Sumner 204424 174773 Doughnut 29651 0.1696544 529 386.43478 Medium Density
Wilson 158805 129918 Doughnut 28887 0.2223479 571 278.11734 Medium Density
Maury 107791 88738 Non-doughnut 19053 0.2147107 613 175.84176 Medium Density
Robertson 75539 67517 Doughnut 8022 0.1188145 476 158.69538 Medium Density
Cheatham 41829 39087 Doughnut 2742 0.0701512 302 138.50662 Medium Density
Dickson 55983 51608 Non-doughnut 4375 0.0847737 490 114.25102 Medium Density
Trousdale 11957 10131 Non-doughnut 1826 0.1802389 114 104.88596 Medium Density
Macon 26240 23261 Non-doughnut 2979 0.1280684 307 85.47231 Low Density
Smith 20389 19389 Non-doughnut 1000 0.0515756 314 64.93312 Low Density
Cannon 14818 13958 Non-doughnut 860 0.0616134 266 55.70677 Low Density
Hickman 25436 24561 Non-doughnut 875 0.0356256 612 41.56209 Low Density

## Code

library(tidyverse)
library(knitr)
library(kableExtra)

County <- c("Cannon", "Cheatham", "Davidson", "Dickson", "Hickman", "Macon",
            "Maury", "Robertson", "Rutherford", "Smith", "Sumner", "Trousdale",
            "Williamson", "Wilson")

CurrentPop <- c(14818, 41829, 715388, 55983, 25436, 26240, 107791, 75539, 360646,
                20389, 204424, 11957, 260351, 158805)

EarlierPop <- c(13958, 39087, 598184, 51608, 24561, 23261, 88738, 67517, 292425,
                19389, 174773, 10131, 208242, 129918)

Region <- c("Non-doughnut", "Doughnut", "Davidson", "Non-doughnut", "Non-doughnut",
            "Non-doughnut", "Non-doughnut", "Doughnut", "Doughnut", "Non-doughnut",
            "Doughnut", "Non-doughnut", "Doughnut", "Doughnut")

Population <- data.frame(
  County,
  CurrentPop,
  EarlierPop,
  Region
)

Population <- Population %>%
  arrange(desc(CurrentPop))

Population <- Population %>%
  mutate(Change = CurrentPop - EarlierPop)

Change_only <- Population %>%
  select(County, Change) %>%
  arrange(desc(Change))

Doughnut <- Population %>%
  filter(Region %in% c("Davidson", "Doughnut")) %>%
  arrange(desc(Change))

Summary <- Population %>%
  group_by(Region) %>%
  summarize(
    CurrentPop = sum(CurrentPop),
    EarlierPop = sum(EarlierPop),
    Change = sum(Change)
  )

Population_v2 <- Population %>%
  mutate(Percent_change = Change / EarlierPop) %>%
  arrange(desc(Percent_change))

TN_Counties <- read_delim(
  "https://www2.census.gov/geo/docs/maps-data/data/gazetteer/2025_Gazetteer/2025_gaz_counties_47.txt",
  delim = "|",
  show_col_types = FALSE
)

Land_Area <- TN_Counties %>%
  transmute(
    County = str_remove(NAME, " County"),
    Square_Miles = round(ALAND_SQMI)
  )

Population_v2 <- left_join(Population_v2, Land_Area, by = "County")

Population_v2 <- Population_v2 %>%
  mutate(Density = CurrentPop / Square_Miles) %>%
  arrange(desc(Density))

Population_v2 <- Population_v2 %>%
  mutate(Density_Category = case_when(
    Density >= 500 ~ "High Density",
    Density >= 100 & Density <= 499 ~ "Medium Density",
    Density < 100 ~ "Low Density"
  ))

Population_v2_table <- Population_v2 %>%
  kbl(caption = "Population_v2") %>%
  kable_styling()