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

