liveBook · Manning

Plot_layout() function

As explained in Statistics Slam Dunk

The plot_layout() function from patchwork specifies how multiple plots are arranged in a composed graphical object.

Use plot_layout() from patchwork to combine separately created plots into one graphical object. Passing ncol = 2 places the plots side by side, making related summaries easier to compare. section 2.5.5

A typical workflow is:

  • Create and store each ggplot object, such as separate mean and median bar charts. section 2.5.5
  • Add the plots with + and specify plot_layout(ncol = 2) to arrange them in two columns. section 2.5.5
  • Read the resulting composite as a coordinated visual comparison, such as average versus median career win shares. section 2.5.5

Place two NBA charts side by side

After defining p5 as an average-win-shares bar chart and p6 as a median-win-shares bar chart, combine them with: p5 + p6 + plot_layout(ncol = 2). The same pattern combines Milwaukee Bucks charts for points scored and field-goal percentage at each second of a possession: MILp1 + MILp2 + plot_layout(ncol = 2). section 2.5.5 section 8.5.1

p5 + p6 + plot_layout(ncol = 2)

Inspect the complete two-column composition combining the average and median win-share plots. section 2.5.5

How Statistics Slam Dunk covers it

How deep it goes
Defines the ncol-based arrangement and demonstrates two-column output, but does not detail broader layout options.
Examples
Combines mean and median win-share charts and Milwaukee Bucks possession charts with ncol = 2.
What it assumes
Assumes familiarity with creating ggplot objects and introduces composition through the + operator and ncol argument.
What you can do after
Apply it via patchwork to place stored plots side by side in a single graphical object.
How it connects
Connects ggplot objects, patchwork, bar charts, line charts, and visual comparison.

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.