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

get_plot_component

Get plot components


Description

Extract plot components from a ggplot or gtable. get_plot_component() extracts grobs or a list of grobs. plot_component_names() provides the names of the components in the plot. plot_components() returns all components as a list.

Usage

get_plot_component(plot, pattern, return_all = FALSE)

plot_component_names(plot)

plot_components(plot)

Arguments

plot

A ggplot or gtable to extract from.

pattern

The name of the component.

return_all

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

Value

A grob or list of grobs (get_plot_component(), plot_components()) or a character vector (plot_component_names())

Examples

library(ggplot2)

p <- ggplot(mpg, aes(displ, cty)) + geom_point()
ggdraw(get_plot_component(p, "ylab-l"))

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.