Skip to contents

This function overlays text annotations onto any ggplot object. It is particularly useful for adding annotations from CSV files generated by the ggsem Shiny app but can also be used with custom annotation data.

Usage

draw_annotations(p, annotations_data, zoom_level = 1)

Arguments

p

A ggplot object. The plot to which the annotations will be added.

annotations_data

A data frame containing annotation information. Typically, this comes from a CSV file generated by the ggsem Shiny app. The required columns include:

  • text: The text to annotate (character).

  • x, y: The coordinates for the text (numeric).

  • font: The font family to use (character, e.g., "serif").

  • size: The size of the text (numeric).

  • color: The color of the text (character, valid hex color).

  • angle: The rotation angle of the text (numeric, in degrees).

  • alpha: The transparency of the text (numeric, 0 to 1).

  • fontface: The font style (character, e.g., "bold").

  • math_expression: Logical, whether the text should be parsed as a mathematical expression.

zoom_level

Numeric. Adjusts the size of annotations based on the zoom level. Default is 1.

Value

A ggplot object with the specified annotations added.

Examples

library(ggplot2)

annotations_data <- data.frame(
text = 'Square One', x = 26, y = 300, font = 'serif',
size = 20, color = '#000000', angle = 0, alpha = 1,
fontface = 'bold', math_expression = FALSE,
lavaan = FALSE, network = FALSE, locked = FALSE
)

p <- ggplot()

draw_annotations(p, annotations_data, zoom_level = 1.2)