library(readr)
library(dplyr)
candidate_paths <- c(
"examples/nhanes-equity/data/nhanes_equity_v6.csv",
"../../examples/nhanes-equity/data/nhanes_equity_v6.csv"
)
nhanes_path <- candidate_paths[file.exists(candidate_paths)][1]
if (is.na(nhanes_path)) {
stop("Could not find examples/nhanes-equity/data/nhanes_equity_v6.csv")
}
nhanes_analysis <- read_csv(nhanes_path, show_col_types = FALSE)
nhanes_analysis |>
summarise(
rows = n(),
missing_bmi = sum(is.na(BMI)),
missing_income = sum(is.na(IncomeGroup))
)Week 6: Data Visualization
Overview
This week turns a descriptive summary into a visual claim. You will use ggplot2 as the core tool, learn how to spot the most common ways a plot misleads a reader, practice prompting an AI co-pilot for plot code you can defend, and finish with a polished figure for Assignment 5.
The emphasis is not decoration. A useful plot makes the statistic, grouping, exclusions, and limitation visible enough that a reader can understand what the figure does and does not support.
-
Required (graded): the seven Assignment 5 files, explained one by one in viz07, plus your part of the M1 proposal
initial-visual-plan.md. - Draft (studio work that feeds A5, not graded on its own): the corrected plot, caption, and audit note from viz06.
- Optional (no penalty for skipping): the alt-text practice in viz07.
Tags like [required] and [optional] are defined in How To Read Submission Lists.
Objectives
By the end of the week you can:
- build a rerunnable
ggplot2visualization from the NHANES Health Equity CSV snapshot; - identify visual choices that can exaggerate, hide, or mislabel a descriptive result;
- revise title, scale, color, grouping, and caption choices to reduce misinterpretation;
- document whether a plot is weighted or unweighted, descriptive or causal, and complete-case or missingness-aware;
- use AI assistance as a draft partner while checking the code and claims yourself.
Connection
Week 5 checked whether simple summaries agree across R and Python. Week 6 asks whether a visual summary is faithful to the evidence. Week 7 then documents the cohort, missingness, and Table 1 behind those same descriptive claims.
Case Study Data Analysis
The NHANES Health Equity data spine now supports code-reading, EDA, visualization, and reproducibility checks. Use the cached CSV/RDS for routine class work; a CDC retrieval script exists for advanced users.
- Cached RDS:
examples/nhanes-equity/data/nhanes_equity_v6.rds - CSV snapshot:
examples/nhanes-equity/data/nhanes_equity_v6.csv - Case-study README:
examples/nhanes-equity/README.md
The default classroom path is to use the cached data so the analysis work is reproducible without internet access.
What to do here: you may run the code below — it loads the cached CSV and prints two small summaries; reading it carefully is enough unless your week’s page asks for more.
Reading order
Work through the pages in order. Each page is short and self-contained.
Class plan
- Read the worked example (viz03) and name the statistic, grouping variable, exclusions, and limitation.
- Inspect the flawed plot code referenced in the studio.
- Identify at least three ways the plot could mislead a reader.
- Revise the plot so the scale, geometry, title, labels, and caption match the evidence.
- Pair-review the corrected caption and check that it does not imply causality or population inference.
Student output
By the end of class each student has a corrected plot, a caption, a short audit note, and an AI-use note if AI helped draft code or wording.
Links
- Assignment: Assignment 5 — Visualization Audit
- Milestone: M1 — Project Proposal (
initial-visual-plan.mdis the connection point)
Definition of done
- The worked example renders from source using a relative path.
- The revised figure has clear labels, an honest scale, and a limitation-aware caption.
- The audit note identifies at least three issues across correctness, design, interpretation, or reproducibility.
- The M1 proposal uses the same standard of transparency for dataset choice, feasibility, and stewardship.
What students leave with
One polished descriptive visualization and a reusable checklist for auditing AI-assisted plots before they appear in a report, dashboard, or slide.