alt-text
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWrite 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
为本项目中的数据可视化和图像生成无障碍替代文本。
参数
- label:(可选)要处理的具体图形标签或代码块
- file:(可选)要处理的具体文件
Detect project type
检测项目类型
Before proceeding, identify the project context and read the relevant reference.
Check for a file in the project root to detect a pkgdown site:
_pkgdown.ymlbash
ls _pkgdown.yml 2>/dev/null && echo "pkgdown" || echo "not pkgdown"- pkgdown site (present) → read
_pkgdown.ymlreferences/pkgdown.md - Quarto documents (no ,
_pkgdown.ymlfiles present) → read.qmdreferences/quarto.md
If the context is still ambiguous, ask the user which format they are working in.
继续操作前,先识别项目上下文并阅读相关参考资料。
检查项目根目录中是否存在 文件,以判断是否为 pkgdown 站点:
_pkgdown.ymlbash
ls _pkgdown.yml 2>/dev/null && echo "pkgdown" || echo "not pkgdown"- pkgdown 站点(存在 )→ 阅读
_pkgdown.ymlreferences/pkgdown.md - Quarto 文档(不存在 ,但存在
_pkgdown.yml文件)→ 阅读.qmdreferences/quarto.md
如果仍无法确定上下文,请询问用户正在使用哪种格式。
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)
三部分结构(Amy Cesal 公式)
- 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 (, ) first. Alt text should complement, not duplicate it:
fig-capfig.cap- 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
先阅读图注(、)。替代文本应当补充图注,而不是重复图注:
fig-capfig.cap- 如果图注已经说明洞察,替代文本可以侧重描述视觉结构
- 如果图注内容笼统,替代文本应包含关键洞察
- 二者结合后,应让人完整理解图表
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)
应包含:
- 以图表类型开头
- 坐标轴标签及其含义
- 代码中揭示了有价值信息时的具体数值/范围(例如,“在 25–50 之间达到峰值”)
- 面板/分面的数量
- 如果使用了颜色或大小,说明其编码的信息
- 支持周边论述的关键模式
不应包含:
- “图像……”或“图表显示……”(屏幕阅读器会播报这类内容)
- 装饰性颜色描述(除非颜色用于编码数据)
- 图注中已有的信息
- 实现细节(包名、函数内部机制)
Length guidelines
长度指南
| Complexity | Sentences | When to use |
|---|---|---|
| Simple | 2–3 | Single geom, no facets, obvious pattern |
| Standard | 3–4 | Multiple geoms or color encoding |
| Complex | 4–5 | Faceted, multiple overlays, nuanced insight |
| 复杂度 | 句数 | 使用场景 |
|---|---|---|
| 简单 | 2–3 | 单一 geom,无分面,模式明显 |
| 标准 | 3–4 | 多个 geom 或使用颜色编码 |
| 复杂 | 4–5 | 分面、多个叠加层,洞察较为细微 |
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")
- 以图表类型开头(散点图、直方图、分面柱状图等)
- 指明坐标轴变量
- 在有助于理解时,包含代码中的具体数值/范围
- 陈述周边文字中的关键洞察
- 补充图注,而不是重复图注
- 对无法看到图像的人也能理解
- 使用通俗语言(避免使用“geom”或“aesthetic”等术语)
Template patterns
模板模式
Scatter chart:
Scatter chart. [X var] along the x-axis, [Y var] along the y-axis.
[Shape: linear/curved/clustered]. [Specific pattern, e.g., "peaks when X is 25–50"].
[Any overlaid fits or annotations].Histogram:
Histogram of [variable]. [Shape: right-skewed/bimodal/normal/uniform].
[If transformed: "after [transformation], the distribution [result]"].
[Notable features: outliers, gaps, multiple modes].Bar chart:
Bar chart. [Categories] along the x-axis, [measure] along the y-axis.
[Key comparison: which is highest/lowest, relative differences].
[Pattern: increasing/decreasing/grouped].Tile/raster chart:
Tile chart [or heatmap]. [Row variable] along the y-axis, [column variable] along the x-axis.
Color encodes [what value]. [Pattern: where values are high/low].
[If faceted: "N panels showing [what varies]"].Faceted chart:
Faceted [chart type] with [N] panels, one per [faceting variable].
[What's constant across panels]. [What changes/varies].
[Key comparison or insight across panels].Correlation heatmap:
Correlation [matrix/heatmap] of [what variables]. [Arrangement].
[Overall pattern: mostly positive/negative/mixed].
[Notable clusters or strong/weak pairs].
[If relevant: contrast with expected behavior].Before/after comparison:
[N] [chart type]s arranged [vertically/in grid]. [Top/Left] shows [original].
[Bottom/Right] shows [transformed]. [Key difference/similarity].
[If overlay: "[color] curve shows [reference]"].Line chart with overlays:
[Line/Scatter] chart with overlaid [fits/curves]. [Axes].
[Number] of [lines/fits] shown: [list what each represents].
[Which fits well vs. poorly and why].散点图:
Scatter chart. [X var] along the x-axis, [Y var] along the y-axis.
[Shape: linear/curved/clustered]. [Specific pattern, e.g., "peaks when X is 25–50"].
[Any overlaid fits or annotations].直方图:
Histogram of [variable]. [Shape: right-skewed/bimodal/normal/uniform].
[If transformed: "after [transformation], the distribution [result]"].
[Notable features: outliers, gaps, multiple modes].柱状图:
Bar chart. [Categories] along the x-axis, [measure] along the y-axis.
[Key comparison: which is highest/lowest, relative differences].
[Pattern: increasing/decreasing/grouped].瓦片图/栅格图:
Tile chart [or heatmap]. [Row variable] along the y-axis, [column variable] along the x-axis.
Color encodes [what value]. [Pattern: where values are high/low].
[If faceted: "N panels showing [what varies]"].分面图表:
Faceted [chart type] with [N] panels, one per [faceting variable].
[What's constant across panels]. [What changes/varies].
[Key comparison or insight across panels].相关性热力图:
Correlation [matrix/heatmap] of [what variables]. [Arrangement].
[Overall pattern: mostly positive/negative/mixed].
[Notable clusters or strong/weak pairs].
[If relevant: contrast with expected behavior].前后对比:
[N] [chart type]s arranged [vertically/in grid]. [Top/Left] shows [original].
[Bottom/Right] shows [transformed]. [Key difference/similarity].
[If overlay: "[color] curve shows [reference]"].带叠加层的折线图:
[Line/Scatter] chart with overlaid [fits/curves]. [Axes].
[Number] of [lines/fits] shown: [list what each represents].
[Which fits well vs. poorly and why].Example
示例
Code context:
r
plotting_data |>
ggplot(aes(value)) +
geom_histogram(binwidth = 0.2) +
facet_grid(name~., scales = "free_y") +
geom_line(aes(x, y), data = norm_curve, color = "green4")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:
Faceted histogram with two panels stacked vertically. Top panel shows
original data with a bimodal distribution. Bottom panel shows the same
data after z-score normalization, retaining the bimodal shape. A green
normal distribution curve overlaid on the bottom panel clearly does not
match the data, demonstrating that normalization preserves distribution
shape rather than creating normality.代码上下文:
r
plotting_data |>
ggplot(aes(value)) +
geom_histogram(binwidth = 0.2) +
facet_grid(name~., scales = "free_y") +
geom_line(aes(x, y), data = norm_curve, color = "green4")周边叙述写道:“归一化并不会让数据更接近正态分布”
图注:“归一化并不会让数据更接近正态分布。绿色曲线表示单位正态分布的密度。”
优秀的替代文本:
Faceted histogram with two panels stacked vertically. Top panel shows
original data with a bimodal distribution. Bottom panel shows the same
data after z-score normalization, retaining the bimodal shape. A green
normal distribution curve overlaid on the bottom panel clearly does not
match the data, demonstrating that normalization preserves distribution
shape rather than creating normality.