liveBook · Manning

Geom_histogram() function

As explained in Statistics Slam Dunk

The geom_histogram() function adds a histogram geometry that bins continuous observations and counts them.

geom_histogram() adds a histogram for one continuous variable. It divides the x-axis into bins, counts observations in each bin, and displays the resulting frequency distribution. section 2.5.3

NBA career win shares

Map WS to x in ggplot(), then add geom_histogram(fill = "royalblue3", color = "royalblue3", bins = 8). Add labs() for titles and axis labels, and print the plot. The resulting histogram shows that career win shares are right-skewed: many first-round picks recorded few win shares, while a small number recorded many. 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)

View a complete ggplot2 histogram combining data mapping, bin count, fill and border colors, labels, theme styling, and output. section 2.5.3

How Statistics Slam Dunk covers it

How deep it goes
Explains binning, counting, styling, labeling, and visual interpretation, but does not detail bin-selection theory.
Examples
Demonstrates eight bins for NBA first-round selections’ career win shares from the 2000–09 drafts.
What it assumes
Assumes a data source and a continuous variable, while introducing ggplot(), aes(), and layered plot construction.
What you can do after
Apply it via ggplot2 to bin continuous observations, count frequencies, style the bars, and assess distribution shape.
How it connects
Connects ggplot(), aes(), labs(), theme(), continuous variables, frequency distributions, and right-skewed distributions.

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.