extract_labs | R Documentation |
Function to extract labels from ggplot2 / patchwork objects
extract_labs(plot, lab_type = c("title", "subtitle", "caption"))
plot |
ggplot2 / patchwork object |
lab_type |
Label type to extract - such as "title", "subtitle", or "caption" |
A length-one character vector
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.