liveBook · Manning

Paired histogram

As explained in Statistics Slam Dunk

A paired histogram is a visualization that places two related histograms together for comparison within a shared plot.

A paired histogram places two related numeric distributions in one plot, making comparison easier than viewing separate charts. It is also called an overlaid histogram. section 15.2

Build a paired histogram by reshaping the data and assigning the two distributions to a grouping variable:

  • Use pivot_longer() to convert games and wins into one counts column, with games identifying the distribution. section 15.3.2
  • Convert the grouping column to a factor and relabel its levels as Played and Won with recode(). section 15.3.2
  • Call gghistogram() with color and fill mapped to the grouping column so overlapping distributions remain visible. section 15.3.2
  • Add means, bin counts, and a rug plot to show central tendency, distribution shape, and individual observations. section 15.3.2

NBA games played versus games won

The NBA franchise data reshapes games and wins into Played and Won values, then compares their distributions across 15 bins. Mean lines and rug marks add context to the frequency patterns. section 15.2 section 15.3.2

p4 <- gghistogram(df3, x = "counts", bins = 15,
  add = "mean", rug = TRUE,
  main = "Distributions of Games Played and Won",
  font.main = "bold", 
  subtitle = "1946-2020", 
  xlab = "Games Played / Games Won", 
  ylab = "Frequency",
  legend.title = "", font.legend = "bold",
  legend = "top",
  color = "games", fill = "games")

Use the complete gghistogram() specification for titles, labels, legend placement, colors, fills, means, bins, and rug marks. section 15.3.2

How Statistics Slam Dunk covers it

How deep it goes
Explains reshaping, recoding, bin selection, mean markers, and rug plots, stopping short of formal statistical inference.
Examples
Uses NBA franchise counts for games played and games won, spanning franchise records from 1946 through 2020.
What it assumes
Assumes basic R data frames and package use while demonstrating tidyverse reshaping, factors, recoding, and distribution displays.
What you can do after
Apply it via ggpubr by reshaping paired measures, overlaying their histograms, and annotating means and observations.
How it connects
Connects histograms with distributions, violin plots, boxplots, rug plots, and data reshaping.

Also explained in

Compare how 2 books explain paired histogram →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Slam Dunk. The section links point to the parts of the book it draws on.