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.
Arguments
- p
A ggplot object to which the self-loop arrows will be added.
- 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
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,
two_way = FALSE, locked = FALSE
)
p <- ggplot()
draw_loops(p, loops_data, zoom_level = 1.2)