extract_labs: Function to extract labels from ggplot2 / patchwork objects

View source: R/extract_labs.R

extract_labsR Documentation

Function to extract labels from ggplot2 / patchwork objects

Description

Function to extract labels from ggplot2 / patchwork objects

Usage

extract_labs(plot, lab_type = c("title", "subtitle", "caption"))

Arguments

plot

ggplot2 / patchwork object

lab_type

Label type to extract - such as "title", "subtitle", or "caption"

Value

A length-one character vector

Examples


## Not run: 
library(ggplot2)

plot1 <- ggplot(economics, aes(x = date, y = unemploy)) +
  geom_point() +
  labs(subtitle = "Plot 1 subtitle")

# Extract the subtitle from plot2
extract_labs(plot1, "subtitle")

# Create a second plot
plot2 <- ggplot(economics, aes(x = date, y = uempmed)) +
  geom_point() +
  labs(subtitle = "Plot 2 subtitle")

# Now combine these plots using patchwork
comb_plots <-
  patchwork::wrap_plots(plot1 + plot2) +
  patchwork::plot_annotation(title = "Combined plot title",
                  caption = "Data source")

extract_labs(comb_plots, "title")

## End(Not run)

djpr-data/djprtheme documentation built on April 15, 2023, 2:47 a.m.