ST 590 Assignment 9

Author

J Sanchez-Collins

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.1     ✔ readr     2.2.0
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.3     ✔ tibble    3.3.1
✔ lubridate 1.9.5     ✔ tidyr     1.3.2
✔ purrr     1.2.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(tidycensus)
library(sf)
Linking to GEOS 3.13.0, GDAL 3.8.5, PROJ 9.5.1; sf_use_s2() is TRUE
library(tigris)
To enable caching of data, set `options(tigris_use_cache = TRUE)`
in your R script or .Rprofile.
library(scales)

Attaching package: 'scales'

The following object is masked from 'package:purrr':

    discard

The following object is masked from 'package:readr':

    col_factor
library(ggplot2)
library(terra)
terra 1.9.11

Attaching package: 'terra'

The following object is masked from 'package:scales':

    rescale

The following object is masked from 'package:tigris':

    blocks

The following object is masked from 'package:tidyr':

    extract
library(mapview)

Part 1: Data Acquisition and Context

I choose to do this assignment on Hillsborough county in Florida for multiple reasons:

  1. It is one of the most highly populated counties in the US with over 1.5 million residents as of 2026.
  2. I saw the name Hillsborough and thought of Hillsborough street.
  3. I was actually born in Tampa, which is inside Hillsborough county.

I wanted to investigate th eproportion of elderly people living there. In order to create a 65+ age variable, I had to select all of the variables for people over the age of 65 for both men and women, which was 12 columns in total. Those variables had to be added together and divided by the total population to create a percentage. I also used data from 2019 to 2024 from the ACS dataset.

#Loading in acs variables
acs_vars <- load_variables(2024, "acs5", cache = TRUE)


#creating a 65+ variable for:
#Hillsborough County, Florida
hills_age <- get_acs(
  geography = "tract",
  variables = c(
    total_people = "B01001_001",
    men_above1   = "B01001_020",
    men_above2   = "B01001_021",
    men_above3   = "B01001_022",
    men_above4   = "B01001_023",
    men_above5   = "B01001_024",
    men_above6   = "B01001_025",
    women_above1 = "B01001_044",
    women_above2 = "B01001_045",
    women_above3 = "B01001_046",
    women_above4 = "B01001_047",
    women_above5 = "B01001_048",
    women_above6 = "B01001_049"
  ),
  state = "FL",
  county = "Hillsborough",
  year = 2024,
  geometry = TRUE,
  output = "wide"
) |>
  transmute(
    GEOID,
    NAME,
    total_above65 = men_above1E + men_above2E + men_above3E + men_above4E + men_above5E + men_above6E + women_above1E + women_above2E + women_above3E + women_above4E + women_above5E + women_above6E,
    total_age = total_peopleE,
    age_percent = total_above65 / total_age,
    geometry
  )
Getting data from the 2020-2024 5-year ACS
Downloading feature geometry from the Census website.  To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.

  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |=                                                                     |   1%
  |                                                                            
  |=                                                                     |   2%
  |                                                                            
  |==                                                                    |   2%
  |                                                                            
  |==                                                                    |   3%
  |                                                                            
  |===                                                                   |   4%
  |                                                                            
  |===                                                                   |   5%
  |                                                                            
  |====                                                                  |   5%
  |                                                                            
  |====                                                                  |   6%
  |                                                                            
  |=====                                                                 |   6%
  |                                                                            
  |=====                                                                 |   7%
  |                                                                            
  |=====                                                                 |   8%
  |                                                                            
  |======                                                                |   8%
  |                                                                            
  |======                                                                |   9%
  |                                                                            
  |=======                                                               |  10%
  |                                                                            
  |========                                                              |  11%
  |                                                                            
  |========                                                              |  12%
  |                                                                            
  |=========                                                             |  12%
  |                                                                            
  |=========                                                             |  13%
  |                                                                            
  |==========                                                            |  14%
  |                                                                            
  |==========                                                            |  15%
  |                                                                            
  |===========                                                           |  15%
  |                                                                            
  |===========                                                           |  16%
  |                                                                            
  |============                                                          |  17%
  |                                                                            
  |============                                                          |  18%
  |                                                                            
  |=============                                                         |  18%
  |                                                                            
  |=============                                                         |  19%
  |                                                                            
  |==============                                                        |  20%
  |                                                                            
  |==============                                                        |  21%
  |                                                                            
  |===============                                                       |  21%
  |                                                                            
  |================                                                      |  22%
  |                                                                            
  |================                                                      |  23%
  |                                                                            
  |=================                                                     |  24%
  |                                                                            
  |==================                                                    |  25%
  |                                                                            
  |==================                                                    |  26%
  |                                                                            
  |===================                                                   |  27%
  |                                                                            
  |====================                                                  |  28%
  |                                                                            
  |====================                                                  |  29%
  |                                                                            
  |=====================                                                 |  30%
  |                                                                            
  |======================                                                |  31%
  |                                                                            
  |======================                                                |  32%
  |                                                                            
  |=======================                                               |  33%
  |                                                                            
  |========================                                              |  34%
  |                                                                            
  |========================                                              |  35%
  |                                                                            
  |=========================                                             |  36%
  |                                                                            
  |==========================                                            |  37%
  |                                                                            
  |===========================                                           |  38%
  |                                                                            
  |===========================                                           |  39%
  |                                                                            
  |============================                                          |  39%
  |                                                                            
  |============================                                          |  40%
  |                                                                            
  |=============================                                         |  41%
  |                                                                            
  |=============================                                         |  42%
  |                                                                            
  |==============================                                        |  42%
  |                                                                            
  |==============================                                        |  43%
  |                                                                            
  |===============================                                       |  44%
  |                                                                            
  |===============================                                       |  45%
  |                                                                            
  |================================                                      |  45%
  |                                                                            
  |================================                                      |  46%
  |                                                                            
  |=================================                                     |  47%
  |                                                                            
  |=================================                                     |  48%
  |                                                                            
  |==================================                                    |  48%
  |                                                                            
  |==================================                                    |  49%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |===================================                                   |  51%
  |                                                                            
  |====================================                                  |  51%
  |                                                                            
  |====================================                                  |  52%
  |                                                                            
  |=====================================                                 |  53%
  |                                                                            
  |======================================                                |  54%
  |                                                                            
  |=======================================                               |  55%
  |                                                                            
  |=======================================                               |  56%
  |                                                                            
  |========================================                              |  57%
  |                                                                            
  |=========================================                             |  58%
  |                                                                            
  |=========================================                             |  59%
  |                                                                            
  |==========================================                            |  60%
  |                                                                            
  |===========================================                           |  61%
  |                                                                            
  |===========================================                           |  62%
  |                                                                            
  |============================================                          |  63%
  |                                                                            
  |=============================================                         |  64%
  |                                                                            
  |=============================================                         |  65%
  |                                                                            
  |==============================================                        |  66%
  |                                                                            
  |===============================================                       |  67%
  |                                                                            
  |===============================================                       |  68%
  |                                                                            
  |================================================                      |  69%
  |                                                                            
  |=================================================                     |  69%
  |                                                                            
  |=================================================                     |  70%
  |                                                                            
  |==================================================                    |  71%
  |                                                                            
  |==================================================                    |  72%
  |                                                                            
  |===================================================                   |  72%
  |                                                                            
  |===================================================                   |  73%
  |                                                                            
  |====================================================                  |  74%
  |                                                                            
  |====================================================                  |  75%
  |                                                                            
  |=====================================================                 |  75%
  |                                                                            
  |=====================================================                 |  76%
  |                                                                            
  |======================================================                |  77%
  |                                                                            
  |======================================================                |  78%
  |                                                                            
  |=======================================================               |  78%
  |                                                                            
  |=======================================================               |  79%
  |                                                                            
  |========================================================              |  80%
  |                                                                            
  |========================================================              |  81%
  |                                                                            
  |=========================================================             |  81%
  |                                                                            
  |=========================================================             |  82%
  |                                                                            
  |==========================================================            |  83%
  |                                                                            
  |===========================================================           |  84%
  |                                                                            
  |============================================================          |  85%
  |                                                                            
  |============================================================          |  86%
  |                                                                            
  |=============================================================         |  87%
  |                                                                            
  |==============================================================        |  88%
  |                                                                            
  |==============================================================        |  89%
  |                                                                            
  |===============================================================       |  90%
  |                                                                            
  |================================================================      |  91%
  |                                                                            
  |================================================================      |  92%
  |                                                                            
  |=================================================================     |  93%
  |                                                                            
  |==================================================================    |  94%
  |                                                                            
  |==================================================================    |  95%
  |                                                                            
  |===================================================================   |  96%
  |                                                                            
  |====================================================================  |  97%
  |                                                                            
  |====================================================================  |  98%
  |                                                                            
  |===================================================================== |  99%
  |                                                                            
  |======================================================================|  99%
  |                                                                            
  |======================================================================| 100%
head(hills_age)
Simple feature collection with 6 features and 5 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: -82.56757 ymin: 27.93388 xmax: -82.10453 ymax: 28.12786
Geodetic CRS:  NAD83
        GEOID                                              NAME total_above65
1 12057004100     Census Tract 41; Hillsborough County; Florida           356
2 12057003600     Census Tract 36; Hillsborough County; Florida           672
3 12057005700     Census Tract 57; Hillsborough County; Florida           719
4 12057012800    Census Tract 128; Hillsborough County; Florida           673
5 12057011413 Census Tract 114.13; Hillsborough County; Florida           825
6 12057011007 Census Tract 110.07; Hillsborough County; Florida           847
  total_age age_percent                       geometry
1      1981   0.1797072 MULTIPOLYGON (((-82.45948 2...
2      4466   0.1504702 MULTIPOLYGON (((-82.41826 2...
3      4872   0.1475780 MULTIPOLYGON (((-82.50574 2...
4      3493   0.1926711 MULTIPOLYGON (((-82.12704 2...
5      6217   0.1327007 MULTIPOLYGON (((-82.56757 2...
6      3625   0.2336552 MULTIPOLYGON (((-82.46304 2...

Part 2: Static Choropleth Map

ggplot(hills_age) +
  geom_sf(aes(fill = age_percent), color = NA) + 
  scale_fill_viridis_c(
    option = "D",
    labels = label_percent(accuracy = 1)
  ) +
  labs(
    title = "There is a low percentage of 65+ adults living in Hillsborough, FL",
    subtitle = "Hillsborough County census tracts, ACS 2019-2024",
    fill = "% 65+ Years Old",
    caption = "Source: ACS via tidycensus"
  ) +
  theme_void() +
  theme(
    plot.title = element_text(face = "bold"),
    plot.title.position = "plot",
    legend.position = "right"
  )

Part 3: Alternative Map Type

#getting variables from acs data
hills_race <- get_acs(
  geography = "tract",
  variables = c(
    White    = "B03002_003",
    Black    = "B03002_004",
    Asian    = "B03002_006",
    Hispanic = "B03002_012"
  ),
  state = "FL",
  county = "Hillsborough",
  year = 2024,
  geometry = TRUE
)
Getting data from the 2020-2024 5-year ACS
Downloading feature geometry from the Census website.  To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
#creating the dots for the map
hills_dots <- hills_race |>
  as_dot_density(
    value = "estimate",
    values_per_dot = 300,
    group = "variable"
  )

hills_background <- hills_race |>
  distinct(GEOID, .keep_all = TRUE)

#dot density map 
ggplot() +
  geom_sf(
    data = hills_background,
    fill = "white",
    color = "gray80",
    linewidth = 0.1
  ) +
  geom_sf(
    data = hills_dots,
    aes(color = variable),
    size = 1,
    alpha = 0.5,
    show.legend = TRUE
  ) +
  scale_color_brewer(palette = "Dark2") +
  labs(
    title = "Race/ethnicity dot plot shows a random spread in Hillsborough",
    subtitle = "Hillsborough County census tracts, one dot = 300 people",
    color = NULL,
    caption = "ACS 2024 via tidycensus"
  ) +
  theme_void() +
  theme(
    plot.title = element_text(face = "bold"),
    plot.title.position = "plot",
    legend.position = "right"
  )

The race density in the county explains the results in the previous map. The population is concentrated in the north and there isn’t much data in the eastern areas, which could explain the lower percentages in the choropleth map.

Part 4: Simple Overlay or Spatial Subset

# Municipal boundaries from tigris
fl_places <- places(state = "FL", cb = TRUE)
Retrieving data for the year 2024

  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |=                                                                     |   2%
  |                                                                            
  |==                                                                    |   3%
  |                                                                            
  |===                                                                   |   5%
  |                                                                            
  |====                                                                  |   6%
  |                                                                            
  |======                                                                |   8%
  |                                                                            
  |=======                                                               |  10%
  |                                                                            
  |========                                                              |  11%
  |                                                                            
  |=========                                                             |  13%
  |                                                                            
  |==========                                                            |  14%
  |                                                                            
  |===========                                                           |  16%
  |                                                                            
  |============                                                          |  18%
  |                                                                            
  |=============                                                         |  19%
  |                                                                            
  |===============                                                       |  21%
  |                                                                            
  |================                                                      |  22%
  |                                                                            
  |=================                                                     |  24%
  |                                                                            
  |==================                                                    |  26%
  |                                                                            
  |===================                                                   |  27%
  |                                                                            
  |====================                                                  |  29%
  |                                                                            
  |=====================                                                 |  30%
  |                                                                            
  |======================                                                |  32%
  |                                                                            
  |=======================                                               |  34%
  |                                                                            
  |=========================                                             |  35%
  |                                                                            
  |==========================                                            |  37%
  |                                                                            
  |===========================                                           |  38%
  |                                                                            
  |============================                                          |  40%
  |                                                                            
  |=============================                                         |  41%
  |                                                                            
  |==============================                                        |  43%
  |                                                                            
  |===============================                                       |  45%
  |                                                                            
  |================================                                      |  46%
  |                                                                            
  |==================================                                    |  48%
  |                                                                            
  |===================================                                   |  49%
  |                                                                            
  |====================================                                  |  51%
  |                                                                            
  |=====================================                                 |  53%
  |                                                                            
  |======================================                                |  54%
  |                                                                            
  |=======================================                               |  56%
  |                                                                            
  |========================================                              |  57%
  |                                                                            
  |=========================================                             |  59%
  |                                                                            
  |==========================================                            |  61%
  |                                                                            
  |============================================                          |  62%
  |                                                                            
  |=============================================                         |  64%
  |                                                                            
  |==============================================                        |  65%
  |                                                                            
  |===============================================                       |  67%
  |                                                                            
  |================================================                      |  69%
  |                                                                            
  |=================================================                     |  70%
  |                                                                            
  |==================================================                    |  72%
  |                                                                            
  |===================================================                   |  73%
  |                                                                            
  |====================================================                  |  75%
  |                                                                            
  |======================================================                |  77%
  |                                                                            
  |=======================================================               |  78%
  |                                                                            
  |========================================================              |  80%
  |                                                                            
  |=========================================================             |  81%
  |                                                                            
  |==========================================================            |  83%
  |                                                                            
  |===========================================================           |  85%
  |                                                                            
  |============================================================          |  86%
  |                                                                            
  |=============================================================         |  88%
  |                                                                            
  |===============================================================       |  89%
  |                                                                            
  |================================================================      |  91%
  |                                                                            
  |=================================================================     |  93%
  |                                                                            
  |==================================================================    |  94%
  |                                                                            
  |===================================================================   |  96%
  |                                                                            
  |====================================================================  |  97%
  |                                                                            
  |===================================================================== |  99%
  |                                                                            
  |======================================================================| 100%
Tampa <- fl_places %>%
  filter(NAME == "Tampa")

# Making sure CRS matches
Tampa <- st_transform(Tampa, st_crs(hills_age))

# Keep tracts that intersect Tampa
tampa_tracts <- st_filter(hills_age, Tampa, .predicate = st_intersects)


ggplot() +
  geom_sf(data = tampa_tracts, aes(fill = age_percent), color = NA) +
  geom_sf(data = Tampa, fill = NA, color = "black", linewidth = 0.5) +  
  scale_fill_viridis_c(labels = label_percent(accuracy = 1)) +
  labs(
    title = "Elderly Population (65+) in Tampa Florida",
    subtitle = "Hillsborough County tracts intersecting the Tampa city boundary",
    fill = "% Age",
    caption = "Source: ACS 2024 via tidycensus; boundary via tigris"
  ) +
  theme_void() +
  theme(
    plot.title = element_text(face = "bold"),
    plot.title.position = "plot"
  )

Part 5: Interactive Map

# Create a display version rounded to 3 decimals
tampa_tracts_map <- tampa_tracts |>
  mutate(age_percent_3 = round(age_percent, 3))

mapview(
  tampa_tracts_map,
  zcol = "age_percent_3",
  layer.name = "Percent 65+"
) + 
  mapview(
    Tampa,
    alpha.regions = .2,
    color = "black",
    lwd = 2,
    layer.name = "Tampa boundary"
  )

Interactivity allows viewers to investigate specific locations and make comparisons between areas. However, in this map specifically, the squares seem arbitrarily drawn about the city and don’t have any location information.

Part 6: Interpretation

Write three substantive takeaways from your maps. Each takeaway should be 1–2 sentences and should refer to a specific visual pattern.

  1. The choropleth map is really good at visualizing continuous variables.
  2. The dot density plot is a good way to add a categorical variable without faceting, especially contrasting and visually distinct colors.
  3. The interactive map is good for incorporating data labels since the cursor only displays one at a time; unlike how a static map like the choropleth would be overcrowded by labels.