Learn R Programming

ggsem (version 0.9.9)

draw_annotations: Draw Text Annotations to a ggplot Object

Description

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(annotations_data, zoom_level = 1)

Value

ggplot2 annotation layers

Arguments

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.

Examples

Run this code
library(ggplot2)

annotations_data <- data.frame(
text = 'x1', x = 9.5, y = 21, font = 'sans',
size = 16, color = '#FFFFFF', fill = NA, angle = 0,
alpha = 1, fontface = 'plain', math_expression = FALSE,
lavaan = FALSE, network = FALSE, locked = FALSE,
group_label = FALSE, loop_label = FALSE, group = 1
)

p <- ggplot()

p + draw_annotations(annotations_data, zoom_level = 1.2)

Run the code above in your browser using DataLab