liveBook · Manning

Theme() function

As explained in Statistics Slam Dunk

The theme() function controls non-data visual styling and presentation settings in a ggplot2 plot.

In ggplot2, theme() controls non-data presentation settings. It can replace defaults with choices such as a bold plot title, while the data mappings and geometric layer remain unchanged. section 2.5.3 section 8.6

Emphasize an NBA histogram title

After building a histogram of career win shares with ggplot(), aes(), geom_histogram(), and labs(), add `theme(plot.title = element_text(face = "bold"))`. The resulting chart uses a bold title while retaining its royal-blue bins and NBA-focused labels. 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 the complete ggplot2 command that combines data mapping, histogram geometry, labels, and title styling. section 2.5.3

How Statistics Slam Dunk covers it

How deep it goes
Demonstrates title-font customization and default overriding without detailing a complete theme system.
Examples
Uses a career win-shares histogram for NBA first-round selections from the 2000–09 drafts.
What it assumes
Assumes basic use of ggplot(), aes(), geoms, and labs() when assembling a plot.
What you can do after
Apply it via ggplot2 to override default plot presentation and emphasize selected visual elements.
How it connects
Connects theme() with ggplot2, geom_histogram(), labs(), and element_text().

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.