Skip to main content

The Superplot

Showing and telling
Method or technique
Intermediate
Line plot of estimates in an interaction, with circles showing group sizes and a line showing the regression of the aggregate averages.
Published

November 9, 2026

Modified

November 13, 2026

Entry #3 in Andrew Gelman’s Handy Statistical Lexicon. Original discussion: Income matters a lot in “red states,” not so much in “blue states”: What’s the matter with Connecticut?.

Filed under Showing and telling · Method or technique · Intermediate.

Related terms: Red State Blue State, ecological fallacy, income and voting.

Source check: ✓ The explanation was checked against the source.

What it is

The superplot is a single graph that shows, together:

  • within-group relationships, as one line per group, for example how the probability of voting Republican rises with income within a state;
  • group sizes, as circles whose area shows how many people sit at each point;
  • the between-group relationship, as a separate line through the group averages.

It became famous through Gelman’s Red State, Blue State analysis. Within every state, richer voters lean Republican. Across states, richer states lean Democratic.

Gelman’s post describes the original plot of Mississippi, Ohio and Connecticut: “Within each state, the line shows the probability of supporting Bush for President for each of five income categories, and the five open circles represent the relative proportion of adults in that state in each category. The black circles show the average income and probability of supporting Bush for each state.”

Why it matters

Within-group and between-group relationships can point in opposite directions. This is the ecological fallacy and its cousin, Simpson’s paradox. If you show only the aggregate line, you will conclude that wealth makes people vote Democratic. If you show only the individual-level regression, you will miss that geography matters. The superplot puts both levels on one canvas, and the circles show which points actually represent many people.

How it works

Fit a model of the outcome on the predictor with group-level effects. Gelman’s post shows two fits: a varying-intercept logistic regression, which keeps the income slopes in the states “essentially parallel”, and an expanded model that lets the slopes vary too, an interaction between income and state, so that “the coefficient for income could differ in richer or poorer states.” For each group, draw its fitted line across the predictor’s range. At each predictor value, place a circle whose area is proportional to the number of people in that group at that value. Finally, draw the regression of group-level average outcomes on group-level average predictors. That line can have the opposite slope.

Simulated example

Three kinds of states (poor, middle-income, rich) have different income distributions. Within each, higher income raises the probability of voting Republican. Move the slider to change how strongly state wealth pushes the whole state toward the Democrats.

Show simulation code

The R version uses base R, and the Python version uses NumPy and Matplotlib. Where the simulation draws random numbers, each language draws its own, so exact numbers differ slightly but show the same pattern. The numbered markers in the R code are explained under it.

import {rng, range, mean, lm, invLogit, fmt} from "../js/stats.js"

viewof stateShift = Inputs.range([0, 1.5], {value: 0.9, step: 0.05, label: "State-wealth effect (toward Dem)"})
viewof within = Inputs.range([0, 0.8], {value: 0.35, step: 0.05, label: "Within-state income slope"})
viewof seed = Inputs.range([1, 500], {value: 3, step: 1, label: "Random seed"})

superSim = {
  const r = rng(seed);
  const groups = [
    {g: "Poor states", center: 2.2, alpha: 0},
    {g: "Middle states", center: 3, alpha: -stateShift / 2},
    {g: "Rich states", center: 3.8, alpha: -stateShift}
  ];
  const people = groups.flatMap(G => range(3000).map(() => {
    const inc = Math.min(5, Math.max(1, Math.round(r.normal(G.center, 1))));
    const p = invLogit(G.alpha + within * (inc - 3));
    return {g: G.g, inc, vote: r.bernoulli(p)};
  }));
  const cells = groups.flatMap(G => [1, 2, 3, 4, 5].map(inc => {
    const c = people.filter(d => d.g === G.g && d.inc === inc);
    return {g: G.g, inc, n: c.length, fit: invLogit(G.alpha + within * (inc - 3))};
  }));
  const agg = groups.map(G => {
    const c = people.filter(d => d.g === G.g);
    return {g: G.g, inc: mean(c.map(d => d.inc)), vote: mean(c.map(d => d.vote))};
  });
  return {cells, agg, between: lm(agg.map(d => d.inc), agg.map(d => d.vote))};
}

Plot.plot({
  ariaLabel: "The Superplot: simulation chart",
  ariaDescription: "Horizontal axis: Income category (1 = poorest, 5 = richest). Vertical axis: Pr(vote Republican). The chart updates with the controls above it, and the summary below the charts states the result in words.",
  height: 360,
  x: {label: "Income category (1 = poorest, 5 = richest)", ticks: 5},
  y: {label: "Pr(vote Republican)", domain: [0, 1], grid: true},
  r: {range: [0, 16]},
  color: {legend: true, domain: ["Poor states", "Middle states", "Rich states"], range: ["#d6604d", "#7f7f7f", "#2166ac"]},
  marks: [
    Plot.line(superSim.cells, {x: "inc", y: "fit", stroke: "g", strokeWidth: 2}),
    Plot.dot(superSim.cells, {x: "inc", y: "fit", r: "n", stroke: "g", fill: "g", fillOpacity: 0.15}),
    Plot.line(superSim.agg, {x: "inc", y: "vote", stroke: "currentColor", strokeWidth: 3, strokeDasharray: "6 4"}),
    Plot.dot(superSim.agg, {x: "inc", y: "vote", fill: "currentColor", r: 5})
  ]
})
# The Superplot: rich people vote Republican, rich states vote Democratic.
1state_shift <- 0.9 # state-wealth effect (toward Democrats)
within <- 0.35 # within-state income slope
2set.seed(3)

centers <- c("Poor states" = 2.2, "Middle states" = 3, "Rich states" = 3.8)
alpha <- c(0, -state_shift / 2, -state_shift)
g <- rep(1:3, each = 3000)
inc <- pmin(5, pmax(1, round(rnorm(9000, centers[g], 1)))) # categories
3vote <- rbinom(9000, 1, plogis(alpha[g] + within * (inc - 3))) # Rep.

avg_inc <- tapply(inc, g, mean)
avg_vote <- tapply(vote, g, mean)
4between <- coef(lm(avg_vote ~ avg_inc))[[2]]
cat("Within each kind of state, richer people vote more Republican.\n",
  "Across state averages, the slope is ", round(between, 3),
  " per income category\n",
  sep = ""
)

cols <- c("#d6604d", "grey50", "#2166ac")
5plot(NA,
  xlim = c(1, 5), ylim = c(0, 1), xlab = "Income category",
  ylab = "Share voting Republican"
)
for (k in 1:3) {
  lines(1:5, plogis(alpha[k] + within * (1:5 - 3)),
    col = cols[k], lwd = 2
  )
}
points(avg_inc, avg_vote, pch = 19, col = cols, cex = 1.5)
lines(avg_inc, avg_vote, lty = 2)
legend("topleft", names(centers), col = cols, lwd = 2, bty = "n")
1
The page’s controls: how much richer states lean Democratic, and the within-state slope of voting on income.
2
Fixes the random numbers so the run is reproducible.
3
Each voter’s choice depends on their own income (richer, more Republican) and on their state (richer state, less Republican).
4
The slope across state averages, which runs the other way.
5
The superplot: one line per kind of state, all sloping up, and the state averages connected by a dashed line sloping down. Both patterns in one picture.
# The Superplot: rich people vote Republican, rich states vote Democratic.
import numpy as np
import matplotlib.pyplot as plt

state_shift = 0.9  # state-wealth effect (toward Democrats)
within = 0.35      # within-state income slope
rng = np.random.default_rng(3)


def inv_logit(v):
    return 1 / (1 + np.exp(-v))


names = ["Poor states", "Middle states", "Rich states"]
centers = np.array([2.2, 3, 3.8])
alpha = np.array([0, -state_shift / 2, -state_shift])
g = np.repeat([0, 1, 2], 3000)
inc = np.clip(np.round(rng.normal(centers[g], 1)), 1, 5)  # categories
vote = rng.binomial(1, inv_logit(alpha[g] + within * (inc - 3)))  # Rep.

avg_inc = np.array([inc[g == k].mean() for k in range(3)])
avg_vote = np.array([vote[g == k].mean() for k in range(3)])
between = np.polyfit(avg_inc, avg_vote, 1)[0]
print("Within each kind of state, richer people vote more Republican.")
print(f"Across state averages, the slope is {between:.3f} per income "
      "category")

x = np.arange(1, 6)
for k, c in enumerate(["#d6604d", "0.5", "#2166ac"]):
    plt.plot(x, inv_logit(alpha[k] + within * (x - 3)), color=c,
             linewidth=2, label=names[k])
    plt.scatter(avg_inc[k], avg_vote[k], s=80, color=c)
plt.plot(avg_inc, avg_vote, "k--")
plt.ylim(0, 1)
plt.xlabel("Income category")
plt.ylabel("Share voting Republican")
plt.legend()
plt.show()

Key takeaways

  • Show within-group and between-group relationships together. They can disagree.
  • Circles sized by group counts show where the population actually is, so readers don’t over-weight sparse cells.
  • The superplot is a remedy for the ecological fallacy drawn as a graph.

Source

Back to top