LAB 3 — TUTORIAL

Spatial Data Integration & Environmental Justice

Download the tutorial file, knit it to see the complete analysis, then run it chunk by chunk to understand each step.

What You Will Build

In this lab you will integrate external point data (environmental facility locations) with your block-group-level economic hardship index. You will align coordinate reference systems, compute the distance from every block group to its nearest facility, overlay facility locations on the hardship map, and test the environmental justice hypothesis: do lower-income communities sit disproportionately close to environmental hazards? You will finish with a multi-buffer comparison that shows how the answer depends on the distance threshold you choose (the Uncertain Geographic Context Problem, UGCoP).

The tutorial walks through every step with fully working code. Knit it first to see the finished product, then go back and run chunk by chunk to understand how it works.

Learning Objectives
  • Load external point data and convert it to sf spatial objects with an aligned CRS
  • Compute distance from block group centroids to the nearest facility with st_distance()
  • Overlay facility locations on a hardship choropleth and map distance to nearest facility
  • Test the environmental justice hypothesis with a distance-decay analysis across distance bands
  • Assess buffer-distance sensitivity (UGCoP) by comparing 0.5-, 1-, and 2-mile buffers

Before You Begin

1 — File and Folder Setup

Create this folder structure before downloading anything. Move the downloaded .qmd into PAF516/Lab3/ before opening it in RStudio.

PAF516/
  Lab1/  Lab2/  ...
  Lab3/
    Lab3_Tutorial.qmd            ← downloaded tutorial (do not edit)
    Lab3_Tutorial.html           ← auto-generated when you knit
    Lab3_Assignment_Howell.qmd   ← your renamed assignment copy
    Lab3_Assignment_Howell.html  ← submit this to Canvas
  Lab4/  Lab5/  ...

2 — Install Packages (Run Once)

Do this before knitting
  1. Open Lab3_Tutorial.qmd in RStudio
  2. Click inside the packages chunk (labeled #| label: packages)
  3. Press Cmd+Return (Mac) or Ctrl+Enter (PC) to run just that chunk
  4. Wait — first run downloads and installs packages and may take 5–10 minutes
  5. After it finishes, future knits will be fast — the renv block only runs once automatically
What is renv?
renv records the exact version of every package used so that code that works today still works next semester.

3 — Census API Key

The lab pulls live data from the Census Bureau. If you don't have a key yet:

  1. Register free at api.census.gov/data/key_signup.html
  2. Check email for your key (arrives within a few minutes)
  3. In the RStudio console run: census_api_key("YOUR_KEY_HERE", install = TRUE)
  4. Restart R: Session → Restart R

Running the Tutorial

Option A — Knit First (Recommended)

Click the Render button (blue arrow, top of editor) or press Cmd+Shift+K / Ctrl+Shift+K. This produces Lab3_Tutorial.html with all results — facility overlay maps, the distance-decay table and charts, and the multi-buffer comparison. Review the output to see what the completed analysis looks like.

Option B — Run Chunk by Chunk (Best for Learning)

Place your cursor inside any code chunk and press the run shortcut. Output appears inline. Fix any errors before moving on. This is how you understand what each step does.

ActionMacPC
Run current chunkCmd+ReturnCtrl+Enter
Run all chunks aboveCmd+Option+PCtrl+Alt+P
Knit / RenderCmd+Shift+KCtrl+Shift+K

What's Inside

StepWhat It Does
Step 1Pull Maricopa County block group data from the 2015–2019 ACS
Step 2Build the 5-variable economic hardship index with z-score standardization
Step 3Load external point data (environmental facility locations)
Step 4Convert point data to sf and align coordinate reference systems
Step 5Compute distance from each block group centroid to the nearest facility with st_distance()
Step 6Facility overlay map and distance-to-nearest-facility choropleth
Step 7Distance-decay analysis — mean hardship and poverty by distance band (the EJ finding)
Step 8Multi-buffer UGCoP comparison — inside vs. outside 0.5-, 1-, and 2-mile buffers

Download

Lab 3 Tutorial File

Download Lab3_Tutorial.qmd

Right-click → Save Link As. Save directly to your PAF516/Lab3/ folder. Do not open in the browser.