A histogram shows the distribution of one continuous variable. It divides the variable’s values into bins, then uses each bin’s height to show how many observations fall inside it. Although it resembles a bar chart, a histogram summarizes continuous data rather than counts of separate categories. section 2.5.3 section 1.2.1
Use a histogram early in exploratory data analysis to make a numeric variable’s shape visible: where values cluster, how spread out they are, and whether unusually large or small values stand apart. It complements basic statistics such as the mean and median and can guide deeper analysis. section 1.3 section 14.3
Build a histogram in ggplot2 by:
- Starting with ggplot(data, aes(x = variable)) to select the data source and map the continuous variable to the x-axis. section 2.5.3
- Adding geom_histogram() to divide x-axis values into bins and count observations in each bin. section 2.5.3
- Choosing a bin count suited to the record count; a practical rule of thumb is roughly the square root of records, with 20 as an upper limit. section 14.3
- Labeling the axes as the measured variable and frequency, then interpreting the resulting distribution rather than treating the chart as a final answer. section 2.5.3
Career win shares of NBA draft selections
A histogram with eight bins displays career win shares for first-round selections from the 2000–09 NBA drafts. The resulting distribution is right-skewed: relatively few players accumulated very high win-share totals, while many accumulated lower totals. Follow-up counts make that picture concrete: 27 players had at least 75 win shares, while 264 had fewer. section 2.5.3
p1 <- ggplot(draft, aes(x = WS)) +
geom_histogram(fill = "royalblue3", color = "royalblue3",
bins = 8) +
labs(title = "Career Win Shares Distribution of
NBA First-Round Selections",
subtitle = "2000-09 NBA Drafts",
x = "Career Win Shares",
y = "Frequency") +
theme(plot.title = element_text(face = "bold"))
print(p1)
This ggplot2 listing builds the win-shares histogram, explicitly setting fill, color, eight bins, and descriptive labels. section 2.5.3
Points per game with reference lines
For 300 team-season observations, a 15-bin histogram plots points scored per game. Dashed and solid vertical lines mark the mean and median, helping assess whether the distribution appears symmetric; a Shapiro-Wilk test then checks that visual impression rather than relying on it alone. section 14.3
Histograms can also compare distributions. Reshape related measurements into a long format, then overlay paired histograms with distinct colors. Mean lines and a rug plot can add detail, though rug plots are most practical for modest-sized data sets. section 15.3.2










