Learn R Programming

ggsem (version 0.9.9)

csv_to_ggplot: Convert CSV Files (from ggsem Shiny App) to a ggplot Object

Description

This function converts the CSV files exported from the ggsem Shiny app into a customizable ggplot object. The resulting plot is compatible with ggplot2 functions, allowing users to modify it further (e.g., adding titles or annotations).

Usage

csv_to_ggplot(
  graphics_data = NULL,
  element_order = c("lines", "points", "loops", "annotations"),
  zoom_level = 1,
  horizontal_position = 0,
  vertical_position = 0,
  n = 100
)

Value

A ggplot object with an axis_ranges attribute specifying the x and y axis ranges after adjustments.

Arguments

graphics_data

A list of data frames containing point data, line data, annotation data, and loop data. It is exported from the ggsem Shiny app. Default is NULL.

element_order

A character vector specifying the order in which graphical elements are added to the plot. For example: c("annotations", "loops", "lines", "points"). Elements at the front appear on top. Default includes all elements.

zoom_level

A numeric value controlling the zoom level of the plot. A value >1 zooms in; <1 zooms out. Default is 1.

horizontal_position

A numeric value to shift the plot horizontally. Default is 0.

vertical_position

A numeric value to shift the plot vertically. Default is 0.

n

Number of points used for interpolation in gradient or curved lines. Default is 100.

Details

- The function uses `coord_fixed` to ensure square plotting space and uniform scaling. - The `element_order` parameter determines the layering of graphical elements, with later elements appearing on top. - The `axis_ranges` attribute is attached to the plot for additional programmatic access.

Examples

Run this code

# CSV files from ggsem app
points_data <- data.frame(
x = 20, y = 20, shape = 'rectangle', color = '#D0C5ED', size = 50,
border_color = '#9646D4', border_width = 2, alpha = 1,
width_height_ratio = 1.6, orientation = 45, lavaan = FALSE,
network = FALSE, locked = FALSE, group = 1
)

lines_data <- data.frame(
x_start = 2, y_start = -2, x_end = 10, y_end = -2, ctrl_x = NA, ctrl_y = NA,
ctrl_x2 = NA, ctrl_y2 = NA, curvature_magnitude = NA, rotate_curvature = NA,
curvature_asymmetry = NA, type = 'Straight Line', color = '#000000',
end_color = NA, color_type = 'Single',
gradient_position = NA, 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, group = 1
)

csv_to_ggplot(graphics_data = list(points_data, lines_data),
              zoom_level = 1.2, # Value from the ggsem app
              horizontal_position = 0, # Value from the ggsem app
              element_order = c('lines', 'points')) # order priority: lines < points


Run the code above in your browser using DataLab