Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

get_panel

Retrieve the panel or part of a panel of a plot


Description

get_panel() extracts just the main panel from a ggplot or a specified panel in a faceted plot. get_panel_component() extracts components from the panel, such as geoms.

Usage

get_panel(plot, panel = NULL, return_all = FALSE)

get_panel_component(panel, pattern)

Arguments

plot

A ggplot or gtable from which to retrieve the panel

panel

An integer indicating which panel to pull. ggplot orders panels column-wise, so this is in order from the top left down.

return_all

If there is more than one panel, should all be returned as a list? Default is FALSE.

pattern

the name of the component

Value

A gtable object holding the panel(s) or a grob of the component

Examples

library(ggplot2)

p <- ggplot(mpg, aes(displ, cty)) + geom_point()
plot_panel <- get_panel(p)
ggdraw(plot_panel)

ggdraw(get_panel_component(plot_panel, "geom_point"))

cowplot

Streamlined Plot Theme and Plot Annotations for 'ggplot2'

v1.1.1
GPL-2
Authors
Claus O. Wilke [aut, cre] (<https://orcid.org/0000-0002-7470-9261>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.