Skip to contents

This function adds a formatted text box to a ggplot using the ggtext package.

Usage

text_box(label, size = 5, ...)

Arguments

label

Text to display in the box. Can include color formatting using square brackets, e.g., "blueBlue text[]".

size

Text size. Default is 5.

...

Additional arguments passed to ggtext::geom_richtext().

Value

A ggplot2 layer object.

Examples

library(ggplot2)
ggplot() +
  text_box(label = "Hello [blue]World[]!", x = 0, y = 0)
#> Error in ggplot_add(object, p, objectname): Can't add `text_box(label = "Hello [blue]World[]!", x = 0, y = 0)` to a
#> <ggplot> object.