View source: R/csv_to_ggplot.R
| csv_to_ggplot | R Documentation |
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).
csv_to_ggplot(
graphics_data = NULL,
element_order = c("lines", "points", "loops", "annotations"),
zoom_level = 1,
horizontal_position = 0,
vertical_position = 0,
n = 100
)
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 |
element_order |
A character vector specifying the order in which graphical elements are added to the plot.
For example: |
zoom_level |
A numeric value controlling the zoom level of the plot. A value >1 zooms in; <1 zooms out. Default is |
horizontal_position |
A numeric value to shift the plot horizontally. Default is |
vertical_position |
A numeric value to shift the plot vertically. Default is |
n |
Number of points used for interpolation in gradient or curved lines. Default is |
- 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.
A ggplot object with an axis_ranges attribute specifying the x and y axis ranges after adjustments.
# 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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.