Skip to contents

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

Usage

geom_text_box(
  label = "Text \n[blue] blue",
  ...,
  size = 5,
  base_color = "black",
  base_fill = "transparent",
  label_size = 1,
  text.color = "black",
  family = "Cambria",
  closest_color = TRUE
)

Arguments

label

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

...

Additional arguments passed to ggtext::geom_richtext().

size

Text size. Default is 5.

base_color

Color of the box border. Default is "black".

base_fill

Fill color of the box. Default is "transparent".

label_size

Size of the label. Default is 1.

text.color

Color of the text. Default is "black".

family

Font family. Default is "Cambria".

closest_color

Logical. If TRUE, uses the closest MNB color for color names. Default is TRUE.

Value

A ggplot2 layer object.

Examples

library(ggplot2)
ggplot() +
  geom_text_box(label = "Hello [blue]World[]!", x = 0, y = 0)