Learn R Programming

ggsem (version 0.9.9)

draw_loops: Draw Self-loop Arrows on a ggplot Object

Description

This function overlays self-loop arrows to a ggplot object based on data describing their positions, sizes, orientations, and styles. Self-loop arrows can be drawn in one direction or bidirectionally with customizable parameters such as color, width, and arrow type. The data can come from a CSV file generated by the ggsem Shiny app or custom input.

Usage

draw_loops(loops_data, zoom_level = 1)

Value

ggplot2 loop layers

Arguments

loops_data

A data frame containing information about the self-loop arrows. The expected columns include:

  • x_center, y_center: Center coordinates of the loop.

  • radius: Radius of the loop.

  • color: Color of the loop (hexadecimal color code).

  • width: Width of the loop line (numeric).

  • alpha: Transparency of the loop line (numeric, 0 to 1).

  • arrow_type: Type of arrow ("closed" or "open").

  • arrow_size: Size of the arrowhead.

  • gap_size: Size of the gap in the loop, specified as a fraction of the full circle (numeric, 0 to 1).

  • loop_width, loop_height: Width and height scaling factors for the loop.

  • orientation: Rotation angle of the loop in degrees.

  • two_way: Logical, whether the loop is bidirectional (adds arrows at both ends).

zoom_level

Numeric. Adjusts the size of line widths and arrowheads relative to the plot. Default is 1.

Examples

Run this code
library(ggplot2)

loops_data <- data.frame(
x_center = -5, y_center = 5, radius = 2, color = '#000000',
width = 1, alpha = 1, arrow_type = 'closed', arrow_size = 0.1,
gap_size = 0.2, loop_width = 5, loop_height = 5, orientation = 0,
lavaan = TRUE, two_way = FALSE, locked = FALSE, group = 1
)

p <- ggplot()

p + draw_loops(loops_data, zoom_level = 1.2)

Run the code above in your browser using DataLab