> "The greatest value of a picture is when it forces us to notice what we never expected to see."
Learning Objectives
- Explain the components of the grammar of graphics (data, aesthetics, geometries, scales, coordinates, facets)
- Select the appropriate chart type for a given analytical question and data structure
- Sketch a chart design on paper specifying axes, marks, and encodings before writing code
- Critique a misleading or poorly designed chart by identifying specific violations of visualization principles
- Distinguish between exploratory visualization (for yourself) and explanatory visualization (for an audience)
In This Chapter
- Chapter Overview
- 14.1 Why Visualization Matters: More Than Pretty Pictures
- 14.2 The Grammar of Graphics: A Language for Charts
- 14.3 Chart Types as Grammar Combinations
- 14.4 The Pie Chart Controversy (And What It Teaches About Perception)
- 14.5 Exploratory vs. Explanatory Visualization
- 14.6 Tufte's Principles: Data-Ink and Chartjunk
- 14.7 When Charts Lie: Recognizing Misleading Visualizations
- 14.8 Sketching Before Coding: The Chart Plan
- 14.9 Matching Questions to Charts: A Decision Framework
- 14.10 The Human Side of Charts: Perception and Cognition
- 14.11 From Theory to Practice: What This Means for Your Code
- 14.12 Putting It All Together: The Chapter in One Diagram
- 14.13 Chapter Summary
- Key Vocabulary Summary
Chapter 14: The Grammar of Graphics — Why Visualization Matters and How to Think About Charts
"The greatest value of a picture is when it forces us to notice what we never expected to see." — John W. Tukey, Exploratory Data Analysis (1977)
Chapter Overview
Take a moment and think about the last time a chart changed your mind about something. Maybe it was a line chart of global temperature anomalies that made climate change feel viscerally real. Maybe it was a bar chart comparing vaccination rates across countries that made you realize how uneven global health coverage truly is. Maybe it was something as mundane as a pie chart at work that finally convinced your boss to reallocate the budget.
Charts are not decorations. They are not the "pretty pictures" phase of data science that you rush through after the "real" analytical work is done. Visualization is a form of thinking. When you plot your data, you see patterns that summary statistics hide. When you design a chart for an audience, you are making an argument — choosing what to emphasize, what to omit, and how to frame a finding so that it lands.
This chapter is different from anything you've done so far in this book. We are going to write almost no code. Instead, we are going to build a mental model for thinking about charts — a grammar of graphics that will make every visualization tool you learn in the next four chapters feel logical rather than arbitrary. By the end of this chapter, you'll be able to look at any chart and decompose it into its parts. You'll be able to sketch a chart on paper before touching a keyboard. And you'll be able to spot when someone is using a chart to mislead you.
In this chapter, you will learn to:
- Explain the components of the grammar of graphics — data, aesthetics, geometries, scales, coordinates, and facets (all paths)
- Select the appropriate chart type for a given analytical question and data structure (all paths)
- Sketch a chart design on paper specifying axes, marks, and encodings before writing code (all paths)
- Critique a misleading or poorly designed chart by identifying specific violations of visualization principles (standard + deep dive paths)
- Distinguish between exploratory visualization (for yourself) and explanatory visualization (for an audience) (all paths)
Note — Learning path annotations: Objectives marked (all paths) are essential for every reader. Those marked (standard + deep dive) can be skimmed on the Fast Track but are important for deeper understanding. See "How to Use This Book" for full path descriptions.
14.1 Why Visualization Matters: More Than Pretty Pictures
Let's start with a fact that may surprise you. In 1973, the statistician Francis Anscombe published a set of four small datasets — now known as Anscombe's Quartet — that have nearly identical summary statistics. Each dataset has the same mean of x, the same mean of y, the same variance of x, the same variance of y, the same correlation between x and y, and the same linear regression line. If you only looked at the numbers, you would conclude these four datasets are essentially the same.
But they're not. Not even close.
When you plot them, one dataset is a clean linear relationship. Another is a perfect curve. The third is a straight line with a single dramatic outlier pulling the regression. And the fourth has all points stacked at the same x-value except for one far-flung observation that single-handedly creates the illusion of a trend.
Anscombe created these datasets to make a single, powerful point: always plot your data. Summary statistics can lie — not intentionally, but through omission. A mean tells you nothing about shape. A correlation coefficient tells you nothing about whether the relationship is actually linear. The only way to see the structure of your data is to look at it.
This lesson lands hard when you've spent the last seven chapters of this book learning to compute means, filter rows, and aggregate groups. All of that work is essential. But it's not complete without visualization. Numbers tell you what. Charts show you why — and sometimes whether — to believe those numbers.
The Power of a Single Chart
We'll explore John Snow's cholera map in detail in Case Study 1, but the short version is this: in 1854, London was in the grip of a cholera epidemic, and the prevailing theory was that the disease spread through "bad air" (miasma). John Snow, a physician, plotted the locations of cholera deaths on a street map and noticed they clustered around a single water pump on Broad Street. That map — a simple dot plot on a city grid — helped overthrow centuries of medical thinking and laid the groundwork for modern epidemiology.
One chart. Hundreds of lives saved. That's the power of visualization done right.
The Danger of a Bad Chart
Conversely, a poorly designed or deliberately misleading chart can deceive millions. Truncated axes that make a small change look enormous. Cherry-picked date ranges that hide inconvenient trends. Three-dimensional bar charts where perspective distortion makes bars look bigger or smaller than they actually are. We'll dissect specific examples in Case Study 2 and throughout Section 14.7, but the takeaway is this: visualization is a superpower, and with it comes responsibility.
Threshold Concept: Charts encode data into visual properties — understanding this mapping is the key to both creating and reading visualizations. A bar's height is not just "tall" or "short" — it represents a number. A point's position on a scatter plot is not just a dot — it encodes two values simultaneously, one on each axis. Every visual element in a well-designed chart carries information. Once you see charts as encodings rather than pictures, you'll never look at a graph the same way again.
14.2 The Grammar of Graphics: A Language for Charts
Imagine you're learning a new spoken language — say, Spanish. One approach is to memorize phrases. "Where is the bathroom?" "Can I have the check?" This gets you through a vacation, but you can't say anything you haven't memorized. The better approach is to learn the grammar — subjects, verbs, objects, tenses, conjugations. Once you understand the grammar, you can construct any sentence you need, including ones you've never heard before.
The same principle applies to data visualization. You could memorize a catalog of chart types: "For comparisons, use a bar chart. For relationships, use a scatter plot. For time trends, use a line chart." And we'll learn those mappings — they're useful. But what really unlocks your ability as a data communicator is understanding the grammar that underlies all charts.
The concept of a grammar of graphics was formalized by Leland Wilkinson in his 1999 book The Grammar of Graphics and later implemented (with important extensions) by Hadley Wickham in the R package ggplot2. The idea is simple and profound: every statistical graphic can be described as a combination of a few fundamental components. Understanding these components lets you construct, deconstruct, and evaluate any chart.
Here are the six core components:
1. Data
Every chart starts with data. This sounds obvious, but it's worth stating explicitly because the choice of which data to include in a chart is itself a design decision. Do you show all countries or just the top ten? Do you include 2020 (a pandemic year that distorts trends) or exclude it? Do you show raw numbers or per-capita rates?
The data component answers: What are we plotting?
For our progressive project, the data might be a pandas DataFrame of vaccination rates by country and year, or a filtered subset showing only Sub-Saharan African countries, or an aggregated summary with one row per WHO region.
2. Aesthetic Mappings
This is the heart of the grammar. An aesthetic mapping connects a variable in your data to a visual property of the chart. The most common aesthetic mappings are:
- x-position: Which variable determines where a mark sits along the horizontal axis?
- y-position: Which variable determines where a mark sits along the vertical axis?
- Color: Which variable determines the color of a mark?
- Size: Which variable determines the size of a mark?
- Shape: Which variable determines the shape of a mark (circle vs. square vs. triangle)?
- Opacity: Which variable determines how transparent a mark is?
For example, in a scatter plot of GDP per capita (x-axis) versus vaccination rate (y-axis) with dots colored by WHO region, the aesthetic mappings are:
| Visual Property | Data Variable |
|---|---|
| x-position | GDP per capita |
| y-position | Vaccination rate |
| color | WHO region |
That's it. Three variables, three mappings. The chart is defined by these connections. Change the mappings and you get a completely different chart, even with the same data.
Key Insight: When someone shows you a chart and asks "what does this mean?", the first thing to identify is the aesthetic mapping. What does position encode? What does color encode? What does size encode? If you can name those mappings, you can read any chart.
3. Geometric Objects (Geoms)
A geometric object — often shortened to "geom" — is the visual mark that represents data on the chart. Common geometric objects include:
| Geom | What It Looks Like | Typical Use |
|---|---|---|
| Point | A dot | Scatter plots, dot plots |
| Line | A connected path | Time series, trend lines |
| Bar | A rectangle anchored to a baseline | Comparisons, frequencies |
| Area | A filled region below a line | Composition over time |
| Box | A box-and-whisker shape | Distribution summaries |
| Text | Characters placed on the chart | Labels, annotations |
The combination of aesthetic mappings and geometric objects gives you the core of any chart. A scatter plot is points with x and y mappings. A bar chart is bars with x (category) and y (value) mappings. A line chart is lines with x (time) and y (value) mappings.
Here's a powerful realization: the same data and aesthetic mappings can produce different charts just by changing the geometric object. Map country to x and vaccination rate to y, and: - With bar geoms, you get a bar chart comparing countries. - With point geoms, you get a dot plot (Cleveland's preferred alternative to the bar chart for many situations). - With text geoms, you get a label chart where country names sit at their values.
The grammar of graphics makes these relationships explicit. You are not choosing from a menu of predetermined chart types; you are assembling a chart from modular components.
4. Scales
A scale controls how data values are translated into visual values. When you map vaccination rate to the y-axis, the scale determines: - What range of the axis corresponds to what range of data? (Does it go from 0 to 100, or from 40 to 90?) - Is the mapping linear, logarithmic, or something else? - What labels appear on the axis? - What colors correspond to what values in a color mapping?
Scales are where many charts go wrong. A bar chart with a y-axis starting at 50 instead of 0 can make a 5-percentage-point difference look like one bar is three times taller than another. A logarithmic scale on an axis can flatten dramatic changes or reveal patterns invisible on a linear scale. We'll return to scale manipulation in Section 14.7 when we talk about misleading charts.
5. Coordinate System
The coordinate system defines the "canvas" on which your chart is drawn. The most common coordinate system is Cartesian — a flat grid with perpendicular x and y axes. But others exist:
- Polar coordinates: The x-axis wraps around in a circle. A bar chart in polar coordinates becomes... a pie chart. (Yes, really. A pie chart is just a stacked bar chart in polar coordinates. This is one of those grammar-of-graphics insights that makes you see charts differently forever.)
- Geographic coordinates: Latitude and longitude, used for maps.
- Flipped Cartesian: The x and y axes are swapped, which turns a vertical bar chart into a horizontal one (often more readable when category labels are long).
For most of the charts you'll build in this course, you'll use standard Cartesian coordinates. But knowing that the coordinate system is a separate, swappable component gives you flexibility.
6. Faceting
Faceting (also called "small multiples" or "trellis plots") splits your data into subgroups and creates a separate mini-chart for each group, all sharing the same axes and scales. For example, instead of plotting all countries on one crowded scatter plot, you could facet by WHO region — producing six small scatter plots, one per region, laid out in a grid.
Faceting is incredibly powerful for comparison. When all the mini-charts share the same scales, your eye can instantly compare patterns across groups. Edward Tufte called small multiples "the best design solution for a wide range of problems in data display." We'll implement faceting in Chapter 16 with seaborn's FacetGrid, but the concept belongs here in the grammar.
Putting It All Together
Here's a complete grammar-of-graphics specification for a chart you might build in Chapter 15:
| Component | Specification |
|---|---|
| Data | WHO vaccination dataset, filtered to 2023, one row per country |
| Aesthetics | x = WHO region, y = vaccination rate (%), color = income group |
| Geom | Bar (grouped) |
| Scales | y-axis: linear, 0 to 100; color: categorical, 4 income groups |
| Coordinates | Cartesian |
| Facets | None (all in one panel) |
That specification fully describes a chart — and you haven't written a line of code yet. This is the power of thinking in grammar rather than in tool-specific function calls. When you later write ax.bar(...) in matplotlib or sns.barplot(...) in seaborn, you'll know exactly what you're building and why, because the design was done before the code.
14.3 Chart Types as Grammar Combinations
Now that you understand the components, let's see how common chart types are just specific combinations of those components. This table will become one of your most-referenced resources throughout Part III.
The Chart Selection Guide
| Your Question | Chart Type | Geom | x-axis | y-axis | Other Aesthetics |
|---|---|---|---|---|---|
| How do categories compare? | Bar chart | Bar | Category | Value | Color (optional) |
| How are two variables related? | Scatter plot | Point | Variable 1 | Variable 2 | Color, size (optional) |
| How does a value change over time? | Line chart | Line | Time | Value | Color for groups |
| What is the distribution of a single variable? | Histogram | Bar (binned) | Value (binned) | Count/frequency | — |
| How do parts make up a whole? | Stacked bar chart | Bar (stacked) | Category | Value | Color = sub-category |
| How does a distribution differ across groups? | Box plot | Box | Category | Value | — |
Let's walk through each of the primary chart types you'll encounter, thinking about when to use each one and — just as importantly — when not to.
Bar Charts: The Workhorse of Comparison
A bar chart uses the length (or height) of rectangular bars to represent values. The bars are anchored to a baseline (usually zero), and the position along the category axis tells you what you're measuring, while the height tells you how much.
When to use it: You want to compare values across a small-to-moderate number of categories. "What are the vaccination rates in each WHO region?" "Which product category has the highest sales?"
When NOT to use it: You have more than about 15-20 categories (the chart gets crowded and unreadable), or you're plotting continuous data that should really be a histogram. Also avoid bar charts for data where the baseline of zero isn't meaningful — if you're comparing temperatures in Fahrenheit, a bar starting at zero is misleading because zero Fahrenheit isn't a meaningful reference point for comparing winter and summer temperatures.
Key design rule: The y-axis of a bar chart should always start at zero. Because bar charts encode values as lengths, truncating the axis distorts the visual comparison. We'll see a dramatic example of this violation in Case Study 2.
Elena's Project: Elena wants to compare vaccination rates across six WHO regions. A bar chart is a natural choice — each region is a category, and the vaccination rate is the value. She considers adding color to distinguish income groups within each region (a grouped bar chart), but decides that might be too busy for a first look. She'll save the grouped version for a deeper analysis.
Scatter Plots: Seeing Relationships
A scatter plot places individual data points on a two-dimensional grid, with one variable on each axis. Each point represents one observation (one country, one patient, one game), and the pattern of points reveals the relationship between the two variables.
When to use it: You want to explore the relationship between two continuous (numerical) variables. "Is there a relationship between GDP per capita and vaccination rate?" "Do countries with higher healthcare spending have better outcomes?"
When NOT to use it: One of your variables is categorical (use a bar chart or box plot instead), or you have so many data points that they merge into an indistinguishable blob (consider a density plot or hexbin plot). Also be careful with scatter plots that invite causal interpretation — just because two variables are correlated in a scatter plot does not mean one causes the other, as we'll explore in Chapter 24.
Key design tip: Color and size can encode additional variables on a scatter plot. Coloring points by WHO region lets you see whether the GDP-vaccination relationship differs across regions. Sizing points by population lets you see whether the pattern is driven by large or small countries. But be judicious — too many encodings make the chart noisy rather than informative.
Line Charts: Tracking Change Over Time
A line chart connects data points with lines, typically with time on the x-axis and a measurement on the y-axis. The connecting line implies continuity — the value transitioned smoothly between the observed points.
When to use it: You want to show how a value changes over a sequential or temporal dimension. "How have vaccination rates changed from 2010 to 2023?" "What does Marcus's weekly revenue look like over a year?"
When NOT to use it: Your x-axis is categorical without a natural order. A line chart of vaccination rates across countries makes no sense because there's no natural ordering from "Brazil" to "Japan" — the connecting lines would imply a transition that doesn't exist. Use a bar chart instead.
Key design tip: Line charts are excellent for comparing multiple series. Plotting vaccination rates for several countries on the same time axis, each in a different color, immediately shows which countries improved and which stagnated. But limit yourself to about 5-7 lines before the chart becomes spaghetti. If you need more, consider faceting (small multiples) instead.
Histograms: Understanding Distributions
A histogram divides a continuous variable into bins (ranges) and plots the count or frequency of observations falling into each bin. Unlike a bar chart, where each bar represents a named category, histogram bars represent ranges of values, and the bars are adjacent (no gaps) to convey continuity.
When to use it: You want to understand the shape of a single variable's distribution. "Are vaccination rates roughly bell-shaped, or skewed? Are there clusters?" "What does the distribution of exam scores look like?" This is fundamentally about understanding the data itself — it's an exploratory tool.
When NOT to use it: You want to compare categories (use a bar chart) or show relationships (use a scatter plot). Also beware that the appearance of a histogram depends heavily on the number of bins you choose — too few and you obscure detail, too many and noise dominates signal. We'll learn techniques for choosing bin widths in Chapter 15.
The critical difference between bar charts and histograms: In a bar chart, the bars represent named categories and can be reordered without changing meaning. In a histogram, the bars represent value ranges along a continuous scale and have a fixed, meaningful order. This distinction trips up many beginners. If your x-axis has labels like "North America" and "Europe," it's a bar chart. If your x-axis has numbers like 0-10, 10-20, 20-30, it's a histogram.
Priya's Project: Priya wants to understand the distribution of three-point attempt rates across all NBA teams. A histogram will show her whether the distribution is normal (most teams clustered around an average), bimodal (two groups with different philosophies), or skewed (a few outlier teams taking many more threes than everyone else). The shape will tell a story that no single summary statistic can.
Other Chart Types to Know About
We've covered the four workhorses — bar, scatter, line, and histogram — in detail because they handle the vast majority of analytical situations. But here are a few more you should be aware of:
-
Box plot (box-and-whisker): Shows the median, quartiles, and potential outliers of a distribution. Excellent for comparing distributions across groups (e.g., vaccination rates by income group). We'll build these in Chapter 16 with seaborn.
-
Heatmap: Uses color intensity in a grid to show the value of a variable across two categorical dimensions. Great for correlation matrices, schedules, or any data with a natural row-column structure.
-
Area chart: Like a line chart, but the region below the line is filled. Useful for showing cumulative totals or composition over time (stacked area chart).
-
Pie chart: A circle divided into slices proportional to values. Controversial among data visualization professionals — we'll discuss why shortly.
14.4 The Pie Chart Controversy (And What It Teaches About Perception)
We need to talk about pie charts. They're everywhere — in business presentations, news articles, annual reports, school projects. And among data visualization professionals, they're the subject of fierce debate.
The criticism of pie charts rests on decades of perceptual research, much of it pioneered by William Cleveland and Robert McGill in their landmark 1984 paper "Graphical Perception: Theory, Experimentation, and Application to the Development of Graphical Methods," published in the Journal of the American Statistical Association. Their experiments showed that people are much better at judging lengths (as in bar charts) than angles (as in pie charts).
Try this thought experiment. Imagine a pie chart with five slices: 22%, 24%, 18%, 20%, and 16%. Can you tell which slice is biggest? Which is second biggest? Now imagine a bar chart with the same five values. The comparison is instant and effortless.
Here's the ranked hierarchy of visual encodings from Cleveland and McGill's research, from most accurate to least:
- Position along a common scale (scatter plots, dot plots)
- Position along non-aligned scales (multiple separate charts)
- Length (bar charts)
- Direction/Angle (pie charts)
- Area (bubble charts, treemaps)
- Volume (3D charts — almost always a bad idea)
- Color saturation / Shading (heatmaps)
Pie charts rely on angle and area — #4 and #5 on this list. Bar charts rely on length — #3. Dot plots rely on position — #1. This is why a simple bar chart almost always communicates the same information more accurately than a pie chart.
Does this mean you should never use a pie chart? No. Pie charts work reasonably well when: - You have only 2-3 slices - One slice is dramatically larger or smaller than the others - Your audience expects a pie chart (sometimes communication trumps perceptual optimality) - You're showing part-to-whole relationships and the point is "this is the majority"
But when in doubt, a bar chart is almost always the better choice. And a 3D pie chart — where perspective distortion makes slices in the front look bigger than equally-sized slices in the back — is never a good choice.
Discussion point: Why do pie charts persist despite being perceptually inferior? Part of the answer is familiarity and aesthetics — people like pie charts and find them visually appealing. Part of it is that tools like Excel make pie charts easy to create. And part of it is that in many communication contexts, precision isn't the goal — a rough sense of proportion is enough, and a pie chart delivers that. Think about when approximate understanding might be acceptable and when precise comparison is essential.
14.5 Exploratory vs. Explanatory Visualization
Here's a distinction that will transform how you think about charts: the difference between exploratory visualization and explanatory visualization.
Exploratory Visualization: Seeing for Yourself
Exploratory visualization is visualization you create for yourself, during the analysis process, to understand your data. It's quick, rough, and disposable. You're not going to show it in a presentation. You're not going to publish it. You're making it so that you can see patterns, spot anomalies, check assumptions, and generate hypotheses.
Characteristics of exploratory visualization: - Speed over beauty. Default colors, default fonts, no title needed — you know what you're looking at. - Many charts, quickly. You might make twenty histograms in five minutes, looking at different variables, different subsets, different bin widths. - Rough and disposable. If a chart doesn't reveal anything interesting, you move on. No time invested in making it pretty. - For discovery. You're asking the data "what's in here?" rather than telling an audience "here's what I found."
This is what you did in Chapter 6 when you first looked at the vaccination data — poking around, checking distributions, looking at means. The visual equivalent of that is exploratory plotting, and we'll do a lot of it in Chapters 15 and 16.
Explanatory Visualization: Communicating to Others
Explanatory visualization is visualization you create for an audience — a boss, a client, a journal reader, a general public — to communicate a specific finding or argument. It's polished, intentional, and designed to make a single point clearly.
Characteristics of explanatory visualization: - One message per chart. An explanatory chart has a clear purpose: "Vaccination rates in Sub-Saharan Africa are 30 percentage points below the global average." Every element of the chart supports that message. - Careful design. Informative title, clear axis labels, appropriate colors, no distracting elements. The chart has been thought about, not just thrown together. - Annotation matters. Key data points are labeled. Reference lines show benchmarks. A subtitle or caption explains the takeaway. - Less is more. Remove everything that doesn't contribute to the message. Edward Tufte called this the data-ink ratio — the proportion of the ink on the page that represents data versus the ink used for borders, backgrounds, gridlines, and decorations.
The Two-Stage Workflow
In practice, most data science visualizations follow a two-stage workflow:
-
Explore: Make many quick, rough charts to understand your data. Try different chart types, different variables, different subsets. Most of these charts will teach you something and then be thrown away.
-
Explain: Once you've found something worth communicating, invest time in designing a polished chart that makes your point clearly, honestly, and memorably.
The mistake many beginners make is trying to do both at once — spending 30 minutes perfecting the axis labels on an exploratory chart they're going to throw away, or rushing an explanatory chart without proper design because they're used to the "just plot it" exploratory mindset.
Elena's Project: When Elena first loads the vaccination data, she'll make dozens of exploratory plots — histograms of every column, scatter plots of every pair, bar charts of every group. Most will be unremarkable. But a few will reveal something: a region with unexpectedly low rates, a year with a sudden drop, a correlation between income and coverage. Those findings become the seeds of explanatory charts that she'll polish for her final report.
14.6 Tufte's Principles: Data-Ink and Chartjunk
No chapter on visualization thinking would be complete without Edward Tufte, arguably the most influential figure in the history of data visualization. His 1983 book The Visual Display of Quantitative Information established principles that every data scientist should know, even if you don't follow all of them rigidly.
The Data-Ink Ratio
Tufte proposed that every element on a chart should be evaluated by asking: Does this represent data? If it doesn't, consider removing it. The data-ink ratio is the proportion of a chart's visual content ("ink") that represents actual data.
data-ink ratio = (ink used to show data) / (total ink on the chart)
A chart with a high data-ink ratio is clean and focused — the reader's attention goes to the data. A chart with a low data-ink ratio is cluttered with gridlines, borders, backgrounds, decorative images, and other non-data elements that compete for attention.
Consider a typical default Excel chart. It often comes with: - A dark border around the plot area - Heavy gridlines - A colored background - A legend box with a border - A 3D effect on the bars
None of these elements represent data. Every one of them can be removed or reduced without losing any information — and doing so makes the data clearer.
Tufte's recommendation: maximize the data-ink ratio. Erase non-data-ink (borders, backgrounds, unnecessary gridlines) and redundant data-ink (if the value is labeled on the bar, you don't also need the y-axis grid line pointing to it). When you do this, the chart gets simpler and the data gets louder.
Chartjunk
Chartjunk is Tufte's term for visual elements that do not convey data and may distract from or distort it. Common examples include:
- Moiré patterns: Vibrating visual textures used to fill bars or areas (common in older software)
- 3D effects: Making bars, pies, or lines three-dimensional, which adds visual complexity without adding information — and often distorts values through perspective
- Decorative illustrations: Clip art, icons, or images overlaid on a chart. A bar chart of oil production where each bar is shaped like an oil barrel looks fun but makes precise comparison nearly impossible because the barrel shape distorts the visual encoding
- Heavy gridlines: Gridlines that are darker or more prominent than the data itself
- Gradient fills: Bars filled with color gradients that make it unclear where the top of the bar is
Tufte's position is clear: chartjunk should be eliminated. Not everyone agrees with him completely — some design researchers have found that moderate use of decorative elements can make charts more memorable and engaging, particularly for general audiences. But as a starting principle, especially for analytical and scientific communication, less is more.
A Practical Application of Tufte's Ideas
Imagine you're building a bar chart of vaccination rates by region for a policy report. Start with the default output from your plotting library. Then apply Tufte's principles:
- Remove the border around the plot area — it's not data.
- Lighten the gridlines to a very faint gray — they help with reading precise values but shouldn't dominate the chart.
- Remove the legend box border — the legend labels are sufficient.
- Make sure the y-axis starts at zero — for bar charts, this is non-negotiable.
- Add a descriptive title that states the finding, not just the topic. Not "Vaccination Rates by Region" but "Sub-Saharan Africa Lags 30 Points Behind the Global Average in Vaccination Coverage."
- Directly label the most important bars instead of relying only on the y-axis for reading values.
- Remove the background color — white or transparent is almost always best.
When you do this in Chapters 15-18, you'll see how a chart transforms from a default blob of visual noise into a clear, focused communication tool.
14.7 When Charts Lie: Recognizing Misleading Visualizations
Visualization is a tool for communication, and like any communication tool, it can be used to inform or to deceive. Sometimes charts mislead through incompetence — the creator didn't know the design was problematic. Sometimes they mislead through deliberate manipulation — the creator knew exactly what they were doing. Either way, you need to be able to spot the tricks.
Here are the most common ways charts mislead:
1. Truncated Y-Axis
This is the single most common technique for making a chart misleading. By starting the y-axis at a value other than zero in a bar chart, small differences are visually amplified. A bar chart showing election approval ratings of 48% and 52% looks like a dead heat when the axis goes 0-100, but looks like a landslide when the axis goes 47-53.
The rule for bar charts: The y-axis must start at zero because bars encode values as lengths. A bar that is twice as tall should represent a value that is twice as large.
The exception for line charts: Line charts encode trends — the slope of the line matters more than its distance from zero. A line chart of stock prices from $150 to $155 is perfectly fine with a y-axis from $148 to $157, because you're showing the change, not the absolute level. But a bar chart of the same data should start at zero.
2. Cherry-Picked Time Ranges
By choosing when a time series starts and ends, you can make almost any trend look like it goes up, down, or stays flat. Want to show that crime is getting worse? Start the chart at the year of a local minimum. Want to show it's getting better? Start at a peak.
The defense: always ask "why does the chart start and end where it does?" and look for longer time ranges that provide context.
3. Dual Y-Axes
A chart with two different y-axes (one on the left, one on the right) can create the illusion of correlation between two unrelated variables. By scaling the two axes independently, you can make any two lines appear to move together or apart. The creator of the chart gets to choose the scale of each axis, and that choice determines the visual relationship.
Tyler Vigen's famous "Spurious Correlations" website illustrates this brilliantly — showing, for instance, a near-perfect visual correlation between per capita cheese consumption and the number of people who died by becoming tangled in their bedsheets. The correlation is real in the statistical sense, but meaningless. The dual-axis presentation makes it look causal.
4. Area Distortion
When images or shapes are used to represent data, scaling them proportionally in both width and height causes the area to grow quadratically. If you double the height of a dollar bill icon to show that spending doubled, the area of the icon is four times larger — visually suggesting a quadruple increase.
This is why infographics that use icons of different sizes are so frequently misleading. A circle with twice the radius has four times the area. The eye perceives area, not radius.
5. Inconsistent Bin Widths in Histograms
If a histogram uses bins of different widths, the visual impression is distorted because the eye reads area rather than height. A wide bin that happens to be tall looks like it contains far more data than it actually does compared to its narrow neighbors.
6. Omitting Context or Baseline
Showing that Company X had 10,000 safety incidents last year sounds alarming. Showing that the industry average is 15,000 and that Company X improved from 18,000 two years ago tells a completely different story. Charts that omit benchmarks, baselines, or context can mislead even when every individual number is correct.
Critical Thinking Framework: When you encounter a chart in the wild — in a news article, a social media post, an annual report — ask yourself these questions: 1. What is the chart trying to say? What's the intended message? 2. Where does the y-axis start? If it's a bar chart, does it start at zero? 3. What time range is shown? Is there a reason it starts or ends where it does? 4. Are there two y-axes? If so, could the scales be manipulated? 5. What is not shown? Is context missing? 6. Who made this chart, and what is their incentive?
14.8 Sketching Before Coding: The Chart Plan
Here's a technique that will save you hours of frustration in Chapters 15-17 and in every data project for the rest of your career: sketch your chart on paper before you write code.
This sounds almost embarrassingly low-tech. You've been learning Python, pandas, and soon matplotlib. Why would you grab a pencil? Because designing a chart is a thinking activity, and code is a poor medium for thinking. When you sit down at a keyboard and start typing plt.plot(...), you're simultaneously making design decisions (what chart type? what goes on each axis?) and fighting with syntax (what's the argument for setting the title? how do I change the color?). The design decisions get lost in the syntax struggle.
When you sketch on paper, all you think about is the design: - What type of chart am I making? - What variable goes on the x-axis? - What variable goes on the y-axis? - What does color represent? - What's the title? - Are there annotations I want to add? - How many panels do I need? - What's the key message?
Here's a simple template for a chart plan:
CHART PLAN
==========
Question: What am I trying to answer or show?
Chart type: Bar / Scatter / Line / Histogram / Other
Data source: Which DataFrame? Any filters?
x-axis: Variable name + label
y-axis: Variable name + label
Color: Variable name (or single color)
Facets: Split by what variable? (or none)
Title: Descriptive title (finding, not just topic)
Annotations: Any callouts, reference lines, labels?
Audience: Who is this for? Exploratory or explanatory?
Project Milestone: For the progressive project, your task at the end of this chapter is to sketch chart designs on paper (or in a simple text document) for each of your vaccination rate research questions. You should have at least 3-5 chart plans ready to implement in Chapter 15. Here's an example:
Chart Plan 1: - Question: How do vaccination rates compare across WHO regions in 2023? - Chart type: Bar chart - Data: vaccination_df filtered to year == 2023, grouped by region - x-axis: WHO region - y-axis: Mean vaccination rate (%) - Color: Single color (blue), highlight Sub-Saharan Africa in orange - Facets: None - Title: "Sub-Saharan Africa's Vaccination Rate Trails Other Regions by 30 Points" - Annotations: Horizontal line at global mean - Audience: Explanatory — for the project report
14.9 Matching Questions to Charts: A Decision Framework
Earlier, we gave a simple table mapping question types to chart types. Now let's build a more detailed decision framework that you can use whenever you're not sure what chart to make.
Step 1: What Is Your Question About?
| Question Focus | Sub-question | Go to |
|---|---|---|
| Comparison | How does this category compare to that one? | Step 2a |
| Relationship | How are these two variables connected? | Step 2b |
| Distribution | What does this variable look like? What's the shape? | Step 2c |
| Composition | What parts make up the whole? | Step 2d |
| Change over time | How does this value change as time passes? | Step 2e |
Step 2a: Comparison
- Few categories (< 8): Horizontal or vertical bar chart
- Many categories (8-20): Horizontal bar chart (labels read easier)
- Very many categories (> 20): Consider filtering to top/bottom N, or use a dot plot
- Comparing across two grouping variables: Grouped bar chart or faceted bar chart
Step 2b: Relationship
- Two continuous variables: Scatter plot
- Two continuous + a category: Scatter plot with color encoding
- Two continuous + another continuous: Scatter plot with size encoding (bubble chart)
- Many variable pairs: Pair plot / scatter matrix (Chapter 16)
- Warning: Correlation is not causation (Chapter 24)
Step 2c: Distribution
- One variable, continuous: Histogram or KDE (kernel density estimate)
- One variable, comparing groups: Overlapping histograms, box plots, or violin plots
- Understanding spread and outliers: Box plot
- Understanding shape in detail: Histogram or KDE
Step 2d: Composition
- Parts of a whole, few categories: Stacked bar chart (or pie chart if 2-3 slices)
- Parts of a whole over time: Stacked area chart
- Hierarchical composition: Treemap (more advanced)
Step 2e: Change Over Time
- One series: Line chart
- 2-5 series: Line chart with color encoding
- Many series (> 5): Faceted line charts (small multiples)
- Emphasizing cumulative total: Area chart
This framework isn't a rigid flowchart — there's always room for creative choices. But it gives you a solid starting point when you're staring at your data and thinking "I don't even know what kind of chart to make."
14.10 The Human Side of Charts: Perception and Cognition
We've talked about the grammar of graphics as a structural framework. But charts are ultimately consumed by human brains, and human brains have specific strengths and weaknesses when it comes to visual processing. Understanding a few key facts about human perception will make you a better chart designer.
Pre-Attentive Processing
Some visual properties are processed by your brain before conscious attention — in under 250 milliseconds, before you even decide to "look" at something. These pre-attentive attributes include:
- Color hue (red among blue pops out instantly)
- Color intensity (dark among light)
- Size (large among small)
- Orientation (tilted among vertical)
- Shape (circle among squares)
- Position (displaced from a line)
This has direct implications for chart design: if you want something to stand out — a key data point, an outlier, a specific category — encode it with a pre-attentive attribute. Make it a different color, make it bigger, or give it a different shape. The reader's eye will go there automatically.
Conversely, if you use pre-attentive attributes for non-essential elements (like making decorative borders bright red), you're hijacking the reader's attention and pulling it away from the data.
Gestalt Principles
The Gestalt principles, developed by early 20th-century psychologists, describe how the brain organizes visual elements into groups and patterns. The most relevant ones for chart design:
- Proximity: Things close together are perceived as a group. This is why grouped bars work — bars near each other are read as belonging to the same category.
- Similarity: Things that look alike are perceived as a group. Color coding leverages this principle — all the blue dots are "the same kind of thing."
- Continuity: The eye follows smooth lines and curves. Line charts work because the brain automatically connects the dots into a trend.
- Enclosure: Things inside a boundary are perceived as a group. Facet borders leverage this — each panel is its own visual context.
- Connection: Things connected by lines are perceived as related. Lines connecting data points in a line chart imply that the points are sequential and related.
You don't need to memorize Gestalt theory, but an awareness of these principles helps explain why certain chart designs work and others don't. A scatter plot with eight colors and no grouping structure is hard to read because nothing triggers the brain's grouping mechanisms. The same data faceted into eight panels is easy to read because enclosure and proximity do the grouping for you.
Color: More Nuanced Than You Think
Color is one of the most powerful visual encodings — and one of the most frequently misused. Here are a few principles:
- Use color for a reason. Don't assign different colors to bars just because it looks "colorful." If all the bars represent the same type of data, they should be the same color. Use different colors only when color encodes a variable.
- Sequential palettes for ordered data. If color represents a value from low to high (like vaccination rate), use a sequential palette — a gradient from light to dark in a single hue (e.g., light blue to dark blue). The light-to-dark mapping is intuitive.
- Diverging palettes for data with a meaningful center. If your data has a meaningful midpoint (like deviation from an average), use a diverging palette — two hues diverging from a neutral center (e.g., blue for below average, red for above, white in the middle).
- Categorical palettes for unordered groups. If color represents a category with no natural ordering (like WHO region), use a set of distinct, visually separable hues. Avoid using sequential palettes for categories — the implied ordering is misleading.
- About 8% of men and 0.5% of women have some form of color vision deficiency. Red-green colorblindness is the most common. Never rely solely on red vs. green to distinguish data. We'll cover accessible color choices in detail in Chapter 18.
14.11 From Theory to Practice: What This Means for Your Code
We've spent this entire chapter thinking about charts without writing code, and that was deliberate. But you may be wondering: how does this grammar of graphics framework connect to the actual Python libraries you're about to learn?
Here's the connection. Every plotting library implements (explicitly or implicitly) the grammar of graphics components:
| Grammar Component | matplotlib (Ch. 15) | seaborn (Ch. 16) | plotly (Ch. 17) |
|---|---|---|---|
| Data | Passed as arrays or from DataFrames | Passed as DataFrame + column names | Passed as DataFrame + column names |
| Aesthetics | Specified via x/y arguments, color/size params | Specified via x/y/hue/size params | Specified via x/y/color/size params |
| Geom | Function choice: plot(), bar(), scatter() |
Function choice: scatterplot(), barplot() |
Function choice: px.scatter(), px.bar() |
| Scales | set_xlim(), set_yscale('log') |
Largely automatic, customizable | Largely automatic, customizable |
| Coordinates | Default Cartesian, projection='polar' |
Inherits from matplotlib | Default Cartesian, geo for maps |
| Facets | plt.subplots() (manual) |
FacetGrid, col/row params |
facet_col, facet_row params |
When you learn matplotlib in Chapter 15, you'll see that the library asks you to think about Figure objects (the canvas), Axes objects (the coordinate system), and the specific plotting functions (the geoms). The terms are different, but the structure maps directly to the grammar.
When you learn seaborn in Chapter 16, you'll see that the library makes the grammar even more explicit — you specify the DataFrame, name the columns for x, y, hue, and size, and the function name determines the geom. Seaborn's design is heavily influenced by the grammar of graphics.
And when you learn plotly in Chapter 17, you'll see a similar pattern with interactive additions. The grammar is universal. Learn it once, and every tool becomes easier.
14.12 Putting It All Together: The Chapter in One Diagram
Here is a summary of the grammar of graphics in the form of a decision and assembly process:
START WITH A QUESTION
|
v
IDENTIFY THE DATA
(What DataFrame? What subset? What aggregation?)
|
v
CHOOSE YOUR AESTHETIC MAPPINGS
(What maps to x? What maps to y? What maps to color/size?)
|
v
CHOOSE YOUR GEOMETRIC OBJECT
(Points? Bars? Lines? Boxes?)
|
v
SET YOUR SCALES
(Linear or log? Start at zero? What color palette?)
|
v
CHOOSE YOUR COORDINATE SYSTEM
(Cartesian? Polar? Geographic?)
|
v
DECIDE ON FACETING
(One panel or multiple? Split by what variable?)
|
v
IS THIS EXPLORATORY OR EXPLANATORY?
| |
v v
EXPLORATORY: EXPLANATORY:
Quick and rough. Polish:
Default settings OK. - Descriptive title (finding, not topic)
Make many, discard most. - Clear axis labels with units
Goal: understand data. - Minimal chartjunk
- Annotations for key findings
- Appropriate for audience
- High data-ink ratio
That's the workflow. Question first, grammar second, code third. If you internalize this workflow, you'll never sit in front of matplotlib wondering "what function do I call?" because the design will already be done.
14.13 Chapter Summary
Let's step back and see what we've learned.
We began with the argument that visualization is not decoration — it's a form of thinking, and one of the most powerful communication tools in the data scientist's toolkit. Anscombe's Quartet showed us that summary statistics alone can deceive, and that you must look at your data to understand it.
We then learned the grammar of graphics: the idea that every chart is composed of data, aesthetic mappings, geometric objects, scales, coordinate systems, and facets. This grammar lets you construct, deconstruct, and evaluate any chart — and makes learning any plotting library easier because you already understand the structure underneath.
We mapped common chart types to the grammar (bar charts as bars with categorical x; scatter plots as points with continuous x and y; line charts as connected lines with temporal x) and built a decision framework for matching questions to chart types.
We grappled with the pie chart controversy and learned Cleveland and McGill's hierarchy of visual encodings. We learned Tufte's principles of data-ink ratio and chartjunk. We explored the critical difference between exploratory and explanatory visualization.
We studied six common ways that charts mislead — truncated axes, cherry-picked time ranges, dual y-axes, area distortion, inconsistent bins, and omitted context — and developed a critical thinking framework for evaluating charts in the wild.
And we learned to sketch charts on paper before writing code, using a chart plan template that ensures the design is done before the syntax battle begins.
In the next chapter, you'll put all of this into practice. matplotlib is waiting, and you'll arrive with a design framework that makes every function call intentional rather than random. You'll know what you're building and why before you type a single character of code.
That's the difference between someone who makes charts and someone who thinks in charts.
Key Vocabulary Summary
| Term | Definition |
|---|---|
| Grammar of graphics | A framework that describes any chart as a combination of data, aesthetic mappings, geometric objects, scales, coordinate systems, and facets |
| Aesthetic mapping | The connection between a variable in your data and a visual property (position, color, size, shape) of the chart |
| Geometric object (geom) | The visual mark (point, line, bar, area) used to represent data on a chart |
| Scale | The rule that translates data values into visual values (e.g., mapping 0-100 to the bottom-to-top of an axis) |
| Coordinate system | The canvas on which marks are placed — Cartesian (rectangular grid), polar (circular), or geographic (map) |
| Faceting | Splitting data into subgroups and creating a separate panel (mini-chart) for each group, with shared axes and scales |
| Chart type | A named chart design (bar, scatter, line, histogram) that corresponds to a specific combination of grammar components |
| Bar chart | A chart using rectangular bars anchored to a baseline to represent values across categories |
| Scatter plot | A chart using points positioned on two continuous axes to show the relationship between two variables |
| Line chart | A chart connecting points with lines to show trends over a sequential dimension (usually time) |
| Histogram | A chart dividing a continuous variable into bins and showing the count or frequency of observations in each bin |
| Exploratory visualization | Quick, rough charts created during analysis to understand the data (for yourself) |
| Explanatory visualization | Polished, intentional charts designed to communicate a specific finding to an audience |
| Data-ink ratio | Tufte's concept: the proportion of a chart's visual content that represents actual data (higher is generally better) |
| Chartjunk | Tufte's term for non-data visual elements that clutter a chart without adding information (3D effects, decorative fills, heavy gridlines) |
Next up: Chapter 15 — matplotlib Foundations: Building Charts from the Ground Up. You've learned the grammar. Now it's time to write in it.
Related Reading
Explore this topic in other books
Intro to Data Science Matplotlib Foundations Introductory Statistics Graphs and Descriptive Statistics Introductory Statistics Communicating with Data Political Analytics Visualizing the Electorate