Infographics
Intro
A good chart starts from a single message, picks the most accurate
visual encoding for the data relationship, and strips everything that
does not support it. Generate standalone SVG with explicit viewBox,
semantic text, and accessible metadata so the result is editable,
responsive, and screen-reader friendly.
Overview
SVG generation principles
- Emit standalone SVG with
xmlns="http://www.w3.org/2000/svg".
- Set an explicit
viewBox (e.g. viewBox="0 0 800 600") for
responsive scaling.
- Use
width="100%" and height="auto" for flexible embedding.
- Group related elements with
<g> and position via transform.
- Put reusable styles in
<defs> and <style> blocks.
- Give elements semantic IDs and classes so the file stays editable.
- Keep text as
<text> elements, not paths, for accessibility.
Data-to-visual mapping
- Identify the message — what should the viewer learn?
- Choose the encoding — position, length, angle, area, color, or
shape.
- Apply visual hierarchy — the most important data gets the
strongest visual treatment.
- Add context — title, axis labels, legend, source attribution.
- Simplify — remove anything that does not support the message.
Encoding effectiveness from most to least accurate for quantitative
data: position > length > angle > area > color saturation > shape.
Chart type selection
| Data Relationship |
Chart Type |
| Change over time |
Line chart, area chart |
| Comparison of categories |
Bar chart (horizontal for many categories) |
| Part-to-whole |
Stacked bar, treemap (avoid pie charts for > 5 slices) |
| Distribution |
Histogram, box plot, violin plot |
| Correlation |
Scatter plot, bubble chart |
| Ranking |
Horizontal bar chart, lollipop chart |
| Flow / process |
Sankey diagram, flowchart |
| Geographic |
Choropleth map, symbol map |
| Hierarchy |
Treemap, sunburst |
Visual design
- Color palette: 3-5 colors max, legible in grayscale.
- Typography: one sans-serif font, clear size hierarchy (title >
subtitle > labels > annotations).
- Whitespace: generous margins and padding prevent clutter.
- Grid lines: light gray, thin, removed when unnecessary.
- Data labels: place directly on chart elements when space
permits to reduce legend lookups.
- Aspect ratio: ~16:9 for presentations, ~4:3 for documents, ~1:1
for social media.
- Mobile first: over 60% of content is consumed on mobile —
prefer vertical layouts.
- One focal point: visuals with a clear focal point outperform
complex ones by roughly 2x in retention.
Accessibility
- 4.5:1 contrast for text, 3:1 for large text and UI elements.
- Never rely solely on color to convey information — add patterns,
labels, or shapes.
- Include
<title> and <desc> for screen readers.
- Use
role="img" and aria-label on the SVG element.
Alternative formats
When SVG is not the right fit, consider Mermaid for flowcharts and
sequence/Gantt diagrams embeddable in Markdown, ASCII art for
terminals and plain-text READMEs, or a CSV plus narrative when the
user just needs organized data with commentary.
Gotchas
Agent-specific failure modes — provider-neutral pause-and-self-check items:
- Omitting the
viewBox attribute. An SVG without viewBox does not scale responsively — it renders at a fixed pixel size that overflows narrow containers and documentation embeds. Always emit viewBox="0 0 W H" with explicit dimensions and use width="100%" and height="auto".
- Positioning
<text> elements without explicit coordinates and alignment attributes. SVG text without x, y, text-anchor, and dominant-baseline renders at the origin or at browser-specific defaults. Lay out every text element explicitly with all four positioning attributes.
- Encoding data in color alone. Roughly 8% of men have red-green color vision deficiency. A chart that differentiates categories only by color is inaccessible. Always pair color with a second encoding: pattern, label, shape, or position.
- Choosing a pie chart for more than 5 slices. The human eye is poor at comparing angles; with many slices, most segments become indistinguishable. Prefer a horizontal bar chart, which exposes differences via length — the most accurate quantitative encoding.
- Omitting
<title> and <desc> elements. Screen readers have no way to announce the chart's content without these elements. Include a <title> stating the chart's finding (not just its topic) and a <desc> summarizing the key data.
- Starting a bar chart's y-axis at a non-zero value. Truncating the axis to exaggerate small differences distorts the viewer's perception of magnitude. For bar charts, the y-axis baseline must be zero.
- Hardcoding
width and height pixel attributes on the root SVG element. A chart with fixed pixel dimensions overflows its container on mobile and cannot be embedded responsively. Use width="100%" and height="auto" and let viewBox drive the aspect ratio.
Full reference
Tufte's core rules
- Show the data — maximize the data-ink ratio (data-ink / total
ink).
- Avoid chartjunk — decorative elements that do not convey
information.
- Use small multiples — repeat a chart design across subsets for
comparison.
- Integrate text and graphics — labels belong on the chart, not
in a distant legend.
Cleveland & McGill encoding ranking
Perceptual accuracy, most to least accurate for quantitative data:
- Position along a common scale
- Position along non-aligned scales
- Length
- Angle / slope
- Area
- Volume / curvature
- Color saturation / shading
- Color hue
Always pick the highest-ranked encoding that fits the relationship.
Color palettes
- Sequential (low to high): single hue, varying lightness (e.g.
#f7fbff to #08306b). Good for heatmaps, choropleths, and
continuous data.
- Diverging (negative to positive with neutral center): two hues
with light center (red-white-blue, brown-white-teal). Good for
deviation from a baseline.
- Categorical: maximally distinct hues at similar lightness.
Limit to 5-7 colors. A safe set:
#4e79a7 #f28e2b #e15759
#76b7b2 #59a14f #edc948 #b07aa1.
- Colorblind safety (~8% of men): avoid red-green as the only
cue. Test with deuteranopia and protanopia simulators. Safe pairs:
blue/orange, blue/red, purple/green.
Typography scale
| Element |
Size (relative) |
Weight |
Case |
| Title |
1.5x base |
Bold |
Sentence |
| Subtitle |
1.2x base |
Regular |
Sentence |
| Axis labels |
1x base |
Medium |
Sentence |
| Tick labels |
0.85x base |
Regular |
As-is |
| Annotations |
0.85x base |
Regular |
Sentence |
| Source note |
0.7x base |
Regular |
Sentence |
SVG layout template
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 800 500"
role="img" aria-label="Chart description">
<title>Chart Title</title>
<desc>Detailed description for screen readers</desc>
<style>
.title { font: bold 24px sans-serif; fill: #1a1a1a; }
.subtitle { font: 16px sans-serif; fill: #666; }
.axis-label { font: 14px sans-serif; fill: #333; }
.tick-label { font: 12px sans-serif; fill: #666; }
.grid-line { stroke: #e0e0e0; stroke-width: 1; }
.data-label { font: 12px sans-serif; fill: #333; }
.source { font: 10px sans-serif; fill: #999; }
</style>
<!-- Margin convention: top=50, right=30, bottom=60, left=80 -->
<g transform="translate(80, 50)">
<!-- Chart content here -->
<!-- Plot area: 690 x 390 -->
</g>
<text x="80" y="30" class="title">Chart Title</text>
<text x="80" y="48" class="subtitle">Supporting context</text>
<text x="80" y="490" class="source">Source: Data source</text>
</svg>
Consistent margins for an 800x500 canvas: top 50 (title and
subtitle), right 30 (breathing room), bottom 60 (x-axis label plus
tick labels), left 80 (y-axis label plus tick labels).
Chart-specific guidelines
- Bar charts: gap between bars 40-50% of bar width. Sort by value
descending unless order is meaningful. Horizontal bars for long
category labels. Always start the y-axis at zero.
- Line charts: cap at 5-7 lines before it gets cluttered. Label
lines directly when possible. Add dots at data points for fewer
than 15 points. Consider area fills for 1-2 series.
- Scatter plots: use 0.3-0.7 opacity when points overlap. Size by
area, not radius. Add a trend line only when the correlation is
meaningful. Label outliers directly.
- Tables (when better than charts): use when precise values
matter more than patterns. Right-align numbers, left-align text.
Subtle row striping for readability. Highlight key values with
bold or color.
Common pitfalls
- Truncated y-axis: non-zero start exaggerates differences.
- 3D effects: distort value perception — always 2D.
- Pie charts: hard to compare — bar charts are more precise.
- Dual y-axes: confusing — use small multiples instead.
- Excessive decoration: chartjunk distracts from data.
- Poor contrast: light colors on white backgrounds.
- Missing units: always label what the numbers mean.
- Rainbow colormaps: perceptually non-uniform — use sequential
or diverging palettes.
Responsive considerations
Use viewBox without fixed width and height for fluid scaling. Test
readability at 50% and 200% zoom. Keep minimum effective text size
around 10px. On mobile, stack small multiples vertically and prefer
horizontal bars.
References
references/best-practices.md — Tufte, Cleveland & McGill, color
palettes, SVG template, and chart-specific guidelines source.
1---2name: infographics3description: Creates data-driven infographics and charts as accessible SVG. Use when visualizing data, choosing a chart type, generating an SVG chart or infographic, or reviewing a visualization for clarity and accuracy.4---56# Infographics78## Intro910A good chart starts from a single message, picks the most accurate11visual encoding for the data relationship, and strips everything that12does not support it. Generate standalone SVG with explicit `viewBox`,13semantic text, and accessible metadata so the result is editable,14responsive, and screen-reader friendly.1516## Overview1718### SVG generation principles1920- Emit standalone SVG with `xmlns="http://www.w3.org/2000/svg"`.21- Set an explicit `viewBox` (e.g. `viewBox="0 0 800 600"`) for22 responsive scaling.23- Use `width="100%"` and `height="auto"` for flexible embedding.24- Group related elements with `<g>` and position via `transform`.25- Put reusable styles in `<defs>` and `<style>` blocks.26- Give elements semantic IDs and classes so the file stays editable.27- Keep text as `<text>` elements, not paths, for accessibility.2829### Data-to-visual mapping30311. **Identify the message** — what should the viewer learn?322. **Choose the encoding** — position, length, angle, area, color, or33 shape.343. **Apply visual hierarchy** — the most important data gets the35 strongest visual treatment.364. **Add context** — title, axis labels, legend, source attribution.375. **Simplify** — remove anything that does not support the message.3839Encoding effectiveness from most to least accurate for quantitative40data: position > length > angle > area > color saturation > shape.4142### Chart type selection4344| Data Relationship | Chart Type |45|---|---|46| Change over time | Line chart, area chart |47| Comparison of categories | Bar chart (horizontal for many categories) |48| Part-to-whole | Stacked bar, treemap (avoid pie charts for > 5 slices) |49| Distribution | Histogram, box plot, violin plot |50| Correlation | Scatter plot, bubble chart |51| Ranking | Horizontal bar chart, lollipop chart |52| Flow / process | Sankey diagram, flowchart |53| Geographic | Choropleth map, symbol map |54| Hierarchy | Treemap, sunburst |5556### Visual design5758- **Color palette:** 3-5 colors max, legible in grayscale.59- **Typography:** one sans-serif font, clear size hierarchy (title >60 subtitle > labels > annotations).61- **Whitespace:** generous margins and padding prevent clutter.62- **Grid lines:** light gray, thin, removed when unnecessary.63- **Data labels:** place directly on chart elements when space64 permits to reduce legend lookups.65- **Aspect ratio:** ~16:9 for presentations, ~4:3 for documents, ~1:166 for social media.67- **Mobile first:** over 60% of content is consumed on mobile —68 prefer vertical layouts.69- **One focal point:** visuals with a clear focal point outperform70 complex ones by roughly 2x in retention.7172### Accessibility7374- 4.5:1 contrast for text, 3:1 for large text and UI elements.75- Never rely solely on color to convey information — add patterns,76 labels, or shapes.77- Include `<title>` and `<desc>` for screen readers.78- Use `role="img"` and `aria-label` on the SVG element.7980### Alternative formats8182When SVG is not the right fit, consider Mermaid for flowcharts and83sequence/Gantt diagrams embeddable in Markdown, ASCII art for84terminals and plain-text READMEs, or a CSV plus narrative when the85user just needs organized data with commentary.8687## Gotchas8889Agent-specific failure modes — provider-neutral pause-and-self-check items:9091- **Omitting the `viewBox` attribute.** An SVG without `viewBox` does not scale responsively — it renders at a fixed pixel size that overflows narrow containers and documentation embeds. Always emit `viewBox="0 0 W H"` with explicit dimensions and use `width="100%"` and `height="auto"`.92- **Positioning `<text>` elements without explicit coordinates and alignment attributes.** SVG text without `x`, `y`, `text-anchor`, and `dominant-baseline` renders at the origin or at browser-specific defaults. Lay out every text element explicitly with all four positioning attributes.93- **Encoding data in color alone.** Roughly 8% of men have red-green color vision deficiency. A chart that differentiates categories only by color is inaccessible. Always pair color with a second encoding: pattern, label, shape, or position.94- **Choosing a pie chart for more than 5 slices.** The human eye is poor at comparing angles; with many slices, most segments become indistinguishable. Prefer a horizontal bar chart, which exposes differences via length — the most accurate quantitative encoding.95- **Omitting `<title>` and `<desc>` elements.** Screen readers have no way to announce the chart's content without these elements. Include a `<title>` stating the chart's finding (not just its topic) and a `<desc>` summarizing the key data.96- **Starting a bar chart's y-axis at a non-zero value.** Truncating the axis to exaggerate small differences distorts the viewer's perception of magnitude. For bar charts, the y-axis baseline must be zero.97- **Hardcoding `width` and `height` pixel attributes on the root SVG element.** A chart with fixed pixel dimensions overflows its container on mobile and cannot be embedded responsively. Use `width="100%"` and `height="auto"` and let `viewBox` drive the aspect ratio.9899## Full reference100101### Tufte's core rules1021031. **Show the data** — maximize the data-ink ratio (data-ink / total104 ink).1052. **Avoid chartjunk** — decorative elements that do not convey106 information.1073. **Use small multiples** — repeat a chart design across subsets for108 comparison.1094. **Integrate text and graphics** — labels belong on the chart, not110 in a distant legend.111112### Cleveland & McGill encoding ranking113114Perceptual accuracy, most to least accurate for quantitative data:1151161. Position along a common scale1172. Position along non-aligned scales1183. Length1194. Angle / slope1205. Area1216. Volume / curvature1227. Color saturation / shading1238. Color hue124125Always pick the highest-ranked encoding that fits the relationship.126127### Color palettes128129- **Sequential** (low to high): single hue, varying lightness (e.g.130 `#f7fbff` to `#08306b`). Good for heatmaps, choropleths, and131 continuous data.132- **Diverging** (negative to positive with neutral center): two hues133 with light center (red-white-blue, brown-white-teal). Good for134 deviation from a baseline.135- **Categorical**: maximally distinct hues at similar lightness.136 Limit to 5-7 colors. A safe set: `#4e79a7` `#f28e2b` `#e15759`137 `#76b7b2` `#59a14f` `#edc948` `#b07aa1`.138- **Colorblind safety** (~8% of men): avoid red-green as the only139 cue. Test with deuteranopia and protanopia simulators. Safe pairs:140 blue/orange, blue/red, purple/green.141142### Typography scale143144| Element | Size (relative) | Weight | Case |145|---|---|---|---|146| Title | 1.5x base | Bold | Sentence |147| Subtitle | 1.2x base | Regular | Sentence |148| Axis labels | 1x base | Medium | Sentence |149| Tick labels | 0.85x base | Regular | As-is |150| Annotations | 0.85x base | Regular | Sentence |151| Source note | 0.7x base | Regular | Sentence |152153### SVG layout template154155```xml156<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 800 500"157 role="img" aria-label="Chart description">158 <title>Chart Title</title>159 <desc>Detailed description for screen readers</desc>160161 <style>162 .title { font: bold 24px sans-serif; fill: #1a1a1a; }163 .subtitle { font: 16px sans-serif; fill: #666; }164 .axis-label { font: 14px sans-serif; fill: #333; }165 .tick-label { font: 12px sans-serif; fill: #666; }166 .grid-line { stroke: #e0e0e0; stroke-width: 1; }167 .data-label { font: 12px sans-serif; fill: #333; }168 .source { font: 10px sans-serif; fill: #999; }169 </style>170171 <!-- Margin convention: top=50, right=30, bottom=60, left=80 -->172 <g transform="translate(80, 50)">173 <!-- Chart content here -->174 <!-- Plot area: 690 x 390 -->175 </g>176177 <text x="80" y="30" class="title">Chart Title</text>178 <text x="80" y="48" class="subtitle">Supporting context</text>179 <text x="80" y="490" class="source">Source: Data source</text>180</svg>181```182183Consistent margins for an 800x500 canvas: top 50 (title and184subtitle), right 30 (breathing room), bottom 60 (x-axis label plus185tick labels), left 80 (y-axis label plus tick labels).186187### Chart-specific guidelines188189- **Bar charts:** gap between bars 40-50% of bar width. Sort by value190 descending unless order is meaningful. Horizontal bars for long191 category labels. Always start the y-axis at zero.192- **Line charts:** cap at 5-7 lines before it gets cluttered. Label193 lines directly when possible. Add dots at data points for fewer194 than 15 points. Consider area fills for 1-2 series.195- **Scatter plots:** use 0.3-0.7 opacity when points overlap. Size by196 area, not radius. Add a trend line only when the correlation is197 meaningful. Label outliers directly.198- **Tables (when better than charts):** use when precise values199 matter more than patterns. Right-align numbers, left-align text.200 Subtle row striping for readability. Highlight key values with201 bold or color.202203### Common pitfalls204205- **Truncated y-axis:** non-zero start exaggerates differences.206- **3D effects:** distort value perception — always 2D.207- **Pie charts:** hard to compare — bar charts are more precise.208- **Dual y-axes:** confusing — use small multiples instead.209- **Excessive decoration:** chartjunk distracts from data.210- **Poor contrast:** light colors on white backgrounds.211- **Missing units:** always label what the numbers mean.212- **Rainbow colormaps:** perceptually non-uniform — use sequential213 or diverging palettes.214215### Responsive considerations216217Use `viewBox` without fixed width and height for fluid scaling. Test218readability at 50% and 200% zoom. Keep minimum effective text size219around 10px. On mobile, stack small multiples vertically and prefer220horizontal bars.221222### References223224- `references/best-practices.md` — Tufte, Cleveland & McGill, color225 palettes, SVG template, and chart-specific guidelines source.