Write Accessible Alt Text
Generate accessible alt text for data visualizations and images in this project.
ARGUMENTS
- label: (optional) specific figure label or chunk to target
- file: (optional) specific file to process
Detect project type
Before proceeding, identify the project context and read the relevant reference.
Check for a _pkgdown.yml file in the project root to detect a pkgdown site:
- pkgdown site (
_pkgdown.ymlpresent) → readreferences/pkgdown.md - Quarto documents (no
_pkgdown.yml,.qmdfiles present) → readreferences/quarto.md
If the context is still ambiguous, ask the user which format they are working in.
Key advantage: source code access
Unlike typical alt text scenarios where you only see an image, we have access to the code that generates each chart. Use this to extract precise details:
From plotting code:
- Variable mappings → exact variable names for axes
- Color/fill mappings → what color encodes
- Plot type functions → scatter, histogram, line chart, etc.
- Trend lines or fitted curves → overlaid statistical fits
- Faceting/subplots → number of panels and what varies
- Color scales → encoding scheme (sequential, diverging, categorical)
- Axis labels and titles → customized labels
From data generation code:
- Random distributions → expected distribution shape
- Transformations → what was done to data
- Feature engineering → preprocessing applied
- Filtering/subsetting → what subset is shown
From surrounding prose:
- Text before/after the chunk explains the purpose and key insight
- Chapter context tells you what the figure is meant to teach
- This is often the best source for the "key insight" part of alt text
Three-part structure (Amy Cesal's formula)
- Chart type — first words identify the format
- Data description — axes, variables, what is shown
- Key insight — the pattern or takeaway (often found in surrounding text)
Relationship to captions
Read the caption (fig-cap, fig.cap) first. Alt text should complement, not duplicate it:
- If the caption states the insight, alt text can focus on describing the visual structure
- If the caption is generic, alt text should include the key insight
- Together they should give a complete understanding
Content rules
Include:
- Chart type as first words
- Axis labels and what they represent
- Specific values/ranges when code reveals them (e.g., "peaks between 25–50")
- Number of panels/facets
- What color/size encodes if used
- The key pattern that supports the surrounding point
Exclude:
- "Image of…" or "Chart showing…" (screen readers announce this)
- Decorative color descriptions (unless color encodes data)
- Information already in the caption
- Implementation details (package names, function internals)
Length guidelines
Quality checklist
- Starts with chart type (Scatter chart, Histogram, Faceted bar chart, etc.)
- Names the axis variables
- Includes specific values/ranges from code when informative
- States the key insight from surrounding prose
- Complements (not duplicates) the caption
- Would make sense to someone who cannot see the image
- Uses plain language (avoid jargon like "geom" or "aesthetic")
Template patterns
Scatter chart:
Histogram:
Bar chart:
Tile/raster chart:
Faceted chart:
Correlation heatmap:
Before/after comparison:
Line chart with overlays:
Example
Code context:
Surrounding prose says: "Normalization doesn't make data more normal"
Caption: "Normalization doesn't make data more normal. The green curve indicates the density of the unit normal distribution."
Good alt text:


