draw_lines {ggsem} | R Documentation |
Draw Lines on a ggplot Object from Line Data
Description
This function overlays lines or arrows to a ggplot object based on line data. It supports straight lines, curved lines, gradient color transitions, and one-way or two-way arrows. The data can come from a CSV file generated by the ggsem Shiny app or custom input.
Usage
draw_lines(p, lines_data, zoom_level = 1, n = n)
Arguments
p |
A ggplot object to which the lines will be added. |
lines_data |
A data frame containing line information. The expected columns include:
|
zoom_level |
Numeric. Adjusts the size of line widths and arrowheads relative to the plot. Default is |
n |
Integer. Number of points for interpolation in gradient or curved lines. Default is |
Value
A ggplot object with the specified lines or arrows added.
Examples
library(ggplot2)
lines_df <- data.frame(
x_start = 2, y_start = -2, x_end = 6, y_end = -2, ctrl_x = NA, ctrl_y = NA,
type = 'Straight Line', color = '#000000', end_color = '#cc3d3d', color_type = 'Gradient',
gradient_position = 0.35, width = 1.5, alpha = 1, arrow = FALSE,
arrow_type = NA, arrow_size = NA, two_way = FALSE, lavaan = FALSE,
network = FALSE, line_style = 'solid', locked = FALSE
)
p <- ggplot()
draw_lines(p, lines_data = lines_df, zoom_level = 1.2, n = 200)