Annotate a composed figure

annotation_forma.RdAdd an overall title, subtitle, and caption with ggforma typography.
Subplot tags use patchwork's native enumeration and nesting rules.
Add the result with + after composing the top-level figure.
Usage
annotation_forma(
title = ggplot2::waiver(),
subtitle = ggplot2::waiver(),
caption = ggplot2::waiver(),
format = c("markdown", "plain", "mixed"),
family = NULL,
lang = NULL,
text_direction = "auto",
width = NULL,
tag_levels = ggplot2::waiver(),
tag_prefix = ggplot2::waiver(),
tag_suffix = ggplot2::waiver(),
tag_sep = ggplot2::waiver(),
theme = NULL
)Arguments
- title, subtitle, caption
Text for the overall figure. Leave a field unspecified to retain it or set it to
NULLto remove it.- format
Text format for the supplied annotations. Use
"plain","markdown", or"mixed". Mixed text supports inline plotmath between dollar signs. A line with double-dollar delimiters can hold a display formula. Seemarkup_grob()for supported rich-text syntax.- family
Font family for the annotations. Use
NULLto inherit it from the theme. Use an installed face or fallback that covers the text.- lang
Optional language tag used for text shaping and line breaking. Supply the complete text when showing more than one language.
- text_direction
Base paragraph direction, one of
"auto","ltr", or"rtl".- width
Optional Grid unit giving the line width for the annotations. Give the figure enough room for the width, text margins and panel slots.
- tag_levels, tag_prefix, tag_suffix, tag_sep
Subplot enumeration settings passed to
patchwork::plot_annotation(). For example, use"A"for letters,"1"for numbers, or a list containing custom tag sequences.- theme
Optional ggplot2 theme for the overall annotation. The supplied text slots use ggforma elements and inherit typography from this theme. Style individual tags through the native patchwork
&operator andtheme(plot.tag = ...).
Details
The annotation belongs to the outermost patchwork. Add it after
combining children with +, |, or /. With align_forma(), add
room for the annotation and the tags when setting the output dimensions.
Use the alignment device or the same backend and settings for export.
Examples
p <- ggplot2::ggplot(mtcars, ggplot2::aes(wt, mpg)) + ggplot2::geom_point()
figure <- (p | p) + annotation_forma(
title = "**Fuel economy**", subtitle = "Mean: $bar(x)$",
caption = "**Source**: mtcars", format = "mixed", tag_levels = "A"
)
if (capabilities("cairo")) {
ggplot2::ggsave(tempfile(fileext = ".pdf"), figure, device = grDevices::cairo_pdf,
width = 180, height = 110, units = "mm")
}