Skip to contents

Use ggplot2's built labels, guide keys, panel summaries and layer-data accessors. Standard wrap and grid facets also expose their formatted strips. A custom strip with no matching variable retains an unknown ID. Markup and formulas remain literal. Mosaic labels are candidates before physical size filtering. The inventory can include hidden axis or legend labels. Third-party grobs and arbitrary text geoms are outside the annotation inventory. Building the plot evaluates its statistics and user callbacks.

Usage

extract_plot_text(
  plot,
  parts = c("labels", "guides", "facets", "categories", "annotations")
)

Arguments

plot

A ggplot object.

parts

One or more of "labels", "guides", "facets", "categories" and "annotations".

Value

A data frame with role, context, stable ID (when known), text, content type, panel, layer and status. Source-only facet rows contain original keys. Only explicitly registered labels have a translation ID.

Examples

p <- ggplot2::ggplot(mtcars, ggplot2::aes(wt, mpg)) +
  ggplot2::geom_point() + ggplot2::labs(title = "Car measurements")
extract_plot_text(p, "labels")
#>    role    context   id             text type panel layer  status
#> 1 label plot.title <NA> Car measurements text    NA    NA display
#> 2 label     plot.x <NA>               wt text    NA    NA display
#> 3 label     plot.y <NA>              mpg text    NA    NA display