| Title: | Publication-Quality Diagrams for Latent Variable Models |
|---|---|
| Description: | Converts output from latent variable model tools into publication-ready path diagrams and model schematics. 'lavaan' fit objects and parameter tables are supported as a primary workflow, with graph adapters for objects from 'blavaan', 'lavaan.mi', 'semPlot', 'mirt', 'eRm', 'OpenMx', 'psych', 'poLCA', 'mclust', 'flexmix', 'lcmm', 'tidyLPA', and 'MplusAutomation' workflows when those packages are available. Supports structural equation and confirmatory factor analysis diagrams, multilevel structural equation models, growth models, higher-order factor models, latent class and profile models, item response theory models, and common mixture outputs through a unified graph grammar with model-aware defaults, geometry diagnostics, layout quality scoring, automatic layout selection, customizable publication styles, 'RStudio' preview, SVG/PDF/PNG export, 'TikZ' output, and reproducible publication bundles. |
| Authors: | Feng Ji [aut, cre] |
| Maintainer: | Feng Ji <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-06-30 21:35:28 UTC |
| Source: | https://github.com/cran/lvmPlot |
Converts latent variable model output into publication-ready path diagrams and
model schematics. lavaan fit objects and parameter tables are supported as
a primary workflow, with adapters for blavaan,
lavaan.mi, semPlot, mirt, eRm, OpenMx,
psych, poLCA, mclust, flexmix, lcmm,
tidyLPA, and MplusAutomation workflows when those packages are
available. The package supports structural equation and confirmatory factor
analysis diagrams, multilevel structural equation models, growth models,
higher-order factor models, latent class and profile schematics, item response
theory models, OpenMx RAM models, and Mplus-style parameter output through a
shared lvm_graph grammar with model-aware defaults, geometry
diagnostics, customizable publication styles, RStudio preview, SVG/PDF/PNG
export, and TikZ output.
plot_lvm, as_lvm_graph,
lvm_graph, lvm_tikz,
plot_sem, sem_tikz
as_sem_graph() reads a lavaan fit object or a lavaan-style parameter
table and returns the node, edge, and layout data used by sem_tikz().
as_sem_graph(object, standardized = TRUE, layout = NULL, residuals = FALSE, covariances = TRUE)as_sem_graph(object, standardized = TRUE, layout = NULL, residuals = FALSE, covariances = TRUE)
object |
A lavaan fit object, or a data frame with at least |
standardized |
Logical. If |
layout |
|
residuals |
Logical. Include variance self-loops from |
covariances |
Logical. Include covariance paths from |
A list with nodes, edges, and parameters, with class
"sem_graph".
check_lvm_layout() is the assertion-style companion to
layout_quality(). It prepares a supported model object as an
lvm_graph, computes geometry and optional label diagnostics, and checks
the result against explicit publication-readiness gates. This is useful in R
Markdown, CI, and manuscript-generation scripts where a diagram should fail
early if nodes, paths, or labels collide.
check_lvm_layout(object, min_score = 92, minimum_status = c("ready", "review", "repair"), max_node_overlaps = 0, max_edge_node_overlaps = 0, max_edge_crossings = NULL, max_label_overlaps = 0, max_label_node_overlaps = 0, max_label_edge_overlaps = 0, label = c("auto", "none", "std", "est", "both"), digits = 2, stars = "auto", respect_curves = TRUE, action = c("error", "warning", "message", "none"), layout = NULL, layout_family = c("auto", "sem", "bifactor", "irt", "mixture", "growth", "multilevel", "circle"), orientation = c("top-down", "bottom-up", "left-right", "right-left"), diagram = c("auto", "all", "measurement", "structural", "loadings", "paths", "covariances", "compact"), show = NULL, min_abs = NULL, significant = NULL, alpha = 0.05, routing = c("straight", "smart", "none"), node_style = NULL, edge_style = NULL, ...)check_lvm_layout(object, min_score = 92, minimum_status = c("ready", "review", "repair"), max_node_overlaps = 0, max_edge_node_overlaps = 0, max_edge_crossings = NULL, max_label_overlaps = 0, max_label_node_overlaps = 0, max_label_edge_overlaps = 0, label = c("auto", "none", "std", "est", "both"), digits = 2, stars = "auto", respect_curves = TRUE, action = c("error", "warning", "message", "none"), layout = NULL, layout_family = c("auto", "sem", "bifactor", "irt", "mixture", "growth", "multilevel", "circle"), orientation = c("top-down", "bottom-up", "left-right", "right-left"), diagram = c("auto", "all", "measurement", "structural", "loadings", "paths", "covariances", "compact"), show = NULL, min_abs = NULL, significant = NULL, alpha = 0.05, routing = c("straight", "smart", "none"), node_style = NULL, edge_style = NULL, ...)
object |
A supported latent variable model object or |
min_score |
Minimum acceptable |
minimum_status |
Minimum acceptable status. |
max_node_overlaps, max_edge_node_overlaps, max_edge_crossings
|
Maximum
allowed hard node/node, edge/node, and edge/edge intersections. Set a limit to
|
max_label_overlaps, max_label_node_overlaps, max_label_edge_overlaps
|
Maximum allowed label collisions when labels are diagnosed. |
label, digits, stars, respect_curves
|
Passed to
|
action |
What to do when the check fails: error, warning, message, or no signal. |
layout |
Optional custom layout. |
layout_family, orientation, diagram, show, min_abs, significant, alpha
|
Passed to the graph-preparation pipeline. |
routing |
Edge routing mode used before scoring. |
node_style, edge_style
|
Optional local style overrides used before scoring. |
... |
Passed to model adapters. |
A lvmPlot_layout_quality object with additional passed,
requirements, violations, graph, and label fields.
params <- data.frame( lhs = c("f", "f", "f"), op = "=~", rhs = c("x1", "x2", "x3"), std.all = c(.7, .8, .75) ) quality <- check_lvm_layout(params, label = "std", action = "none") quality$passedparams <- data.frame( lhs = c("f", "f", "f"), op = "=~", rhs = c("x1", "x2", "x3"), std.all = c(.7, .8, .75) ) quality <- check_lvm_layout(params, label = "std", action = "none") quality$passed
export_lvm_bundle() writes a complete manuscript-ready diagram bundle:
vector/raster graphics, standalone TikZ, graph tables, diagnostics, quality
report, and reproducibility metadata. It is intended to make the diagram a
reproducible research artifact rather than a one-off image.
export_lvm_bundle(object, dir, name = "lvmPlot-diagram", formats = c("pdf", "png", "svg", "tex"), width = "auto", height = "auto", res = 300, layout = NULL, layout_family = c("auto", "sem", "bifactor", "irt", "mixture", "growth", "multilevel", "circle"), orientation = c("top-down", "bottom-up", "left-right", "right-left"), diagram = c("auto", "all", "measurement", "structural", "loadings", "paths", "covariances", "compact"), show = NULL, min_abs = NULL, significant = NULL, alpha = 0.05, label = c("auto", "std", "est", "both", "none"), digits = 2, stars = "auto", node_labels = NULL, theme = lvm_theme_names(), style = NULL, node_style = NULL, edge_style = NULL, routing = c("straight", "smart", "none"), aspect = c("balanced", "preserve", "fill"), margin = 0.08, optimize = FALSE, optimize_layout_family = "auto", optimize_orientation = c("top-down", "left-right", "bottom-up", "right-left"), optimize_diagram = "auto", optimize_routing = "straight", tables = TRUE, diagnostics = TRUE, check = FALSE, check_min_score = 92, check_status = c("ready", "review", "repair"), check_max_edge_crossings = NULL, check_action = c("error", "warning", "message", "none"), metadata = TRUE, report = TRUE, compile_tex = FALSE, engine = c("pdflatex", "xelatex", "lualatex", "tectonic"), ...)export_lvm_bundle(object, dir, name = "lvmPlot-diagram", formats = c("pdf", "png", "svg", "tex"), width = "auto", height = "auto", res = 300, layout = NULL, layout_family = c("auto", "sem", "bifactor", "irt", "mixture", "growth", "multilevel", "circle"), orientation = c("top-down", "bottom-up", "left-right", "right-left"), diagram = c("auto", "all", "measurement", "structural", "loadings", "paths", "covariances", "compact"), show = NULL, min_abs = NULL, significant = NULL, alpha = 0.05, label = c("auto", "std", "est", "both", "none"), digits = 2, stars = "auto", node_labels = NULL, theme = lvm_theme_names(), style = NULL, node_style = NULL, edge_style = NULL, routing = c("straight", "smart", "none"), aspect = c("balanced", "preserve", "fill"), margin = 0.08, optimize = FALSE, optimize_layout_family = "auto", optimize_orientation = c("top-down", "left-right", "bottom-up", "right-left"), optimize_diagram = "auto", optimize_routing = "straight", tables = TRUE, diagnostics = TRUE, check = FALSE, check_min_score = 92, check_status = c("ready", "review", "repair"), check_max_edge_crossings = NULL, check_action = c("error", "warning", "message", "none"), metadata = TRUE, report = TRUE, compile_tex = FALSE, engine = c("pdflatex", "xelatex", "lualatex", "tectonic"), ...)
object |
A supported latent variable model object or |
dir |
Output directory. |
name |
File stem used for exported artifacts. |
formats |
Character vector of graphic formats. Supported values are
|
width, height
|
Device size in inches, or |
res |
PNG resolution in pixels per inch. |
layout |
Optional custom layout. |
layout_family |
Layout family. |
orientation |
Diagram orientation. |
diagram |
Diagram subset. |
show |
Optional edge types to show. |
min_abs |
Optional absolute loading/path threshold. |
significant |
Logical. Keep only significant estimated edges. |
alpha |
Significance threshold. |
label |
Edge label style. |
digits |
Number of digits for edge labels. |
stars |
Significance-star policy. |
node_labels |
Optional node relabeling vector or function. |
theme |
Diagram theme. |
style |
Style overrides from |
node_style, edge_style
|
Optional per-node and per-edge style tables. |
routing |
Edge routing mode. |
aspect |
Plot coordinate scaling. |
margin |
Outer plot margin. |
optimize |
Logical. If |
optimize_layout_family, optimize_orientation, optimize_diagram, optimize_routing
|
Candidate
settings used when |
tables |
Logical. Write node and edge CSV tables. |
diagnostics |
Logical. Write diagnostic and quality CSV files. |
check |
Logical. If |
check_min_score |
Minimum acceptable quality score when
|
check_status |
Minimum acceptable status when |
check_max_edge_crossings |
Optional maximum edge crossings when
|
check_action |
Signal used when |
metadata |
Logical. Write reproducibility metadata and session info. |
report |
Logical. Write a human-readable Markdown report. |
compile_tex |
Logical. Compile the TikZ file when |
engine |
TeX engine used when |
... |
Passed to model adapters. |
A list with exported files, quality summary, graph, and device size, with class
"lvmPlot_bundle".
params <- data.frame( lhs = c("f", "f", "f"), op = "=~", rhs = c("x1", "x2", "x3"), std.all = c(.7, .8, .75) ) out <- tempfile("lvmPlot-bundle-") export_lvm_bundle( params, out, name = "cfa", formats = c("pdf", "tex"), check = TRUE, optimize = TRUE, optimize_orientation = c("top-down", "left-right") )params <- data.frame( lhs = c("f", "f", "f"), op = "=~", rhs = c("x1", "x2", "x3"), std.all = c(.7, .8, .75) ) out <- tempfile("lvmPlot-bundle-") export_lvm_bundle( params, out, name = "cfa", formats = c("pdf", "tex"), check = TRUE, optimize = TRUE, optimize_orientation = c("top-down", "left-right") )
layout_diagnostics() scores the current node coordinates before
drawing. It is useful for checking whether a complex SEM/LVM layout still has
node overlaps, straight-edge crossings, edge/node collisions, or estimated
parameter label collisions before export.
layout_diagnostics( object, respect_curves = TRUE, label = c("none", "auto", "std", "est", "both"), digits = 2, stars = "auto" )layout_diagnostics( object, respect_curves = TRUE, label = c("none", "auto", "std", "est", "both"), digits = 2, stars = "auto" )
object |
An |
respect_curves |
Logical. If |
label |
Edge label mode used for optional label diagnostics. The default
|
digits |
Number of digits for estimated label text. |
stars |
Significance-star policy used when |
A list with node overlap counts, edge crossing counts, edge/node overlap counts,
optional edge-label collision counts, edge length summaries, and detail data
frames, with class "lvmPlot_layout_diagnostics".
nodes <- data.frame( name = c("a", "b", "middle"), type = "observed", x = c(0, 2, 1), y = c(0, 0, 0) ) edges <- data.frame(from = "a", to = "b", type = "path") graph <- lvm_graph(nodes, edges) layout_diagnostics(graph, respect_curves = FALSE) layout_diagnostics(graph, respect_curves = FALSE, label = "est")nodes <- data.frame( name = c("a", "b", "middle"), type = "observed", x = c(0, 2, 1), y = c(0, 0, 0) ) edges <- data.frame(from = "a", to = "b", type = "path") graph <- lvm_graph(nodes, edges) layout_diagnostics(graph, respect_curves = FALSE) layout_diagnostics(graph, respect_curves = FALSE, label = "est")
layout_matrix() converts a familiar SEM plotting matrix into explicit
node coordinates. Rows are interpreted from top to bottom and columns from left
to right.
layout_matrix(x, x_spacing = 1.8, y_spacing = 1.7)layout_matrix(x, x_spacing = 1.8, y_spacing = 1.7)
x |
A matrix or data frame whose non-empty cells contain node names. Empty
cells may be |
x_spacing, y_spacing
|
Spacing between columns and rows in diagram coordinates. |
A data frame with name, x, and y columns.
layout <- layout_matrix(matrix( c(NA, "f", NA, "x1", ".", "x2"), nrow = 2, byrow = TRUE )) layoutlayout <- layout_matrix(matrix( c(NA, "f", NA, "x1", ".", "x2"), nrow = 2, byrow = TRUE )) layout
layout_quality() turns layout_diagnostics() into a compact quality
score and issue table. It is designed for publication workflows where a diagram
should be checked before being exported or submitted.
layout_quality(object, label = c("none", "auto", "std", "est", "both"), digits = 2, stars = "auto", respect_curves = TRUE)layout_quality(object, label = c("none", "auto", "std", "est", "both"), digits = 2, stars = "auto", respect_curves = TRUE)
object |
A |
label |
Edge label mode used for optional label diagnostics. |
digits |
Number of digits for estimated label text. |
stars |
Significance-star policy used when |
respect_curves |
Logical. If |
A list with score, grade, status, issues, and
diagnostics, with class "lvmPlot_layout_quality".
params <- data.frame( lhs = c("f", "f", "f"), op = "=~", rhs = c("x1", "x2", "x3"), std.all = c(.7, .8, .75) ) quality <- layout_quality(as_lvm_graph(params), label = "std") qualityparams <- data.frame( lhs = c("f", "f", "f"), op = "=~", rhs = c("x1", "x2", "x3"), std.all = c(.7, .8, .75) ) quality <- layout_quality(as_lvm_graph(params), label = "std") quality
lvm_canvas_size() inspects the prepared graph coordinates and returns a
recommended device size. It helps dense MIRT/LCA diagrams get wider canvases and
multilevel diagrams get taller canvases without manually guessing export
dimensions.
lvm_canvas_size(object, ..., min_width = 6, max_width = 14, min_height = 4, max_height = 9.5)lvm_canvas_size(object, ..., min_width = 6, max_width = 14, min_height = 4, max_height = 9.5)
object |
A supported latent variable model object or |
... |
Plot/layout arguments passed as they would be to |
min_width, max_width
|
Width bounds in inches. |
min_height, max_height
|
Height bounds in inches. |
A named numeric vector with width and height, in inches.
params <- data.frame( lhs = c("visual", "visual", "visual", "textual", "textual", "textual"), op = "=~", rhs = paste0("x", 1:6), est = .7 ) lvm_canvas_size(params)params <- data.frame( lhs = c("visual", "visual", "visual", "textual", "textual", "textual"), op = "=~", rhs = paste0("x", 1:6), est = .7 ) lvm_canvas_size(params)
lvm_graph() is the common diagram grammar used by SEM, LCA/LPA,
multilevel SEM, IRT/MIRT, growth, mixture, and adapter-based model diagrams.
Model-specific adapters convert fitted model objects to this graph structure
before drawing.
lvm_graph(nodes, edges = data.frame(), model_type = "lvm", layout_family = NULL, title = NULL, meta = list()) as_lvm_graph(object, ...)lvm_graph(nodes, edges = data.frame(), model_type = "lvm", layout_family = NULL, title = NULL, meta = list()) as_lvm_graph(object, ...)
nodes |
Data frame of nodes. Needs a |
edges |
Data frame of edges with |
model_type |
Short model family label. |
layout_family |
Layout family used when coordinates are absent. |
title |
Optional graph title. |
meta |
Optional metadata list. |
object |
A supported model object, parameter table, or graph object. |
... |
Passed to methods. |
An object of class "lvm_graph".
Creates style overrides for plot_lvm(), plot_sem(),
lvm_tikz(), and sem_tikz().
lvm_style(scale = NULL, node_scale = NULL, edge_scale = NULL, font_scale = NULL, node_font_size = NULL, edge_font_size = NULL, font_family = NULL, latent_size = NULL, observed_width = NULL, observed_height = NULL, node_line_width = NULL, edge_line_width = NULL, path_line_width = NULL, loading_line_width = NULL, covariance_line_width = NULL, residual_line_width = NULL, node_color = NULL, latent_color = NULL, observed_color = NULL, node_fill = NULL, latent_fill = NULL, observed_fill = NULL, edge_color = NULL, path_color = NULL, loading_color = NULL, covariance_color = NULL, residual_color = NULL, node_text_color = NULL, label_color = NULL, label_fill = NULL)lvm_style(scale = NULL, node_scale = NULL, edge_scale = NULL, font_scale = NULL, node_font_size = NULL, edge_font_size = NULL, font_family = NULL, latent_size = NULL, observed_width = NULL, observed_height = NULL, node_line_width = NULL, edge_line_width = NULL, path_line_width = NULL, loading_line_width = NULL, covariance_line_width = NULL, residual_line_width = NULL, node_color = NULL, latent_color = NULL, observed_color = NULL, node_fill = NULL, latent_fill = NULL, observed_fill = NULL, edge_color = NULL, path_color = NULL, loading_color = NULL, covariance_color = NULL, residual_color = NULL, node_text_color = NULL, label_color = NULL, label_fill = NULL)
scale |
Overall multiplier for node dimensions, line widths, and text sizes. |
node_scale |
Multiplier for latent and observed node dimensions. |
edge_scale |
Multiplier for edge line widths. |
font_scale |
Multiplier for node and edge label font sizes. |
node_font_size |
Node label font size in points. |
edge_font_size |
Edge label font size in points. |
font_family |
Font family for grid output. For TikZ, use |
latent_size |
Latent node diameter in millimeters. |
observed_width, observed_height
|
Observed node size in millimeters. |
node_line_width |
Stroke width for latent and observed nodes. |
edge_line_width |
Stroke width for all edges. |
path_line_width, loading_line_width, covariance_line_width, residual_line_width
|
Stroke widths for specific edge types. |
node_color, latent_color, observed_color
|
Stroke colors. |
node_fill, latent_fill, observed_fill
|
Fill colors. |
edge_color, path_color, loading_color, covariance_color, residual_color
|
Edge colors. |
node_text_color |
Node-label text color. |
label_color, label_fill
|
Edge-label text and background colors. |
A named list with class "lvm_style".
style <- lvm_style( scale = 1.08, font_scale = 0.95, node_font_size = 12, edge_font_size = 9, latent_size = 16, observed_width = 20, node_fill = "#F8FAFC", edge_line_width = 1.1 )style <- lvm_style( scale = 1.08, font_scale = 0.95, node_font_size = 12, edge_font_size = 9, latent_size = 16, observed_width = 20, node_fill = "#F8FAFC", edge_line_width = 1.1 )
lvm_themes() returns the built-in theme presets accepted by
plot_lvm(), plot_sem(), lvm_tikz(), and
sem_tikz(). The default theme is "journal".
lvm_themes()lvm_themes()
A data frame with theme names and short descriptions.
lvm_themes()lvm_themes()
Creates editable TikZ output from the unified LVM graph grammar.
lvm_tikz(object, layout = NULL, layout_family = c("auto", "sem", "bifactor", "irt", "mixture", "growth", "multilevel", "circle"), orientation = c("top-down", "bottom-up", "left-right", "right-left"), diagram = c("auto", "all", "measurement", "structural", "loadings", "paths", "covariances", "compact"), show = NULL, min_abs = NULL, significant = NULL, alpha = 0.05, label = c("auto", "std", "est", "both", "none"), digits = 2, stars = "auto", node_labels = NULL, standalone = FALSE, theme = lvm_theme_names(), style = NULL, node_style = NULL, edge_style = NULL, routing = c("straight", "smart", "none"), escape = TRUE, file = NULL, ...) write_lvm_tikz(object, file, standalone = TRUE, compile = FALSE, engine = c("pdflatex", "xelatex", "lualatex", "tectonic"), clean = TRUE, ...)lvm_tikz(object, layout = NULL, layout_family = c("auto", "sem", "bifactor", "irt", "mixture", "growth", "multilevel", "circle"), orientation = c("top-down", "bottom-up", "left-right", "right-left"), diagram = c("auto", "all", "measurement", "structural", "loadings", "paths", "covariances", "compact"), show = NULL, min_abs = NULL, significant = NULL, alpha = 0.05, label = c("auto", "std", "est", "both", "none"), digits = 2, stars = "auto", node_labels = NULL, standalone = FALSE, theme = lvm_theme_names(), style = NULL, node_style = NULL, edge_style = NULL, routing = c("straight", "smart", "none"), escape = TRUE, file = NULL, ...) write_lvm_tikz(object, file, standalone = TRUE, compile = FALSE, engine = c("pdflatex", "xelatex", "lualatex", "tectonic"), clean = TRUE, ...)
object |
A supported model object, |
layout |
Optional custom layout, either a data frame with |
layout_family |
Layout preset, including SEM, bifactor, IRT, mixture, growth, multilevel, and circle layouts. |
orientation |
Diagram direction. |
diagram |
Diagram preset used to filter edge types. |
show |
Optional explicit edge-type or diagram-type set to show. |
min_abs |
Optional minimum absolute estimate/standardized estimate. |
significant |
If |
alpha |
Significance threshold. |
label |
Edge label style: automatic, standardized estimates, raw
estimates, both, or no labels. |
digits |
Number of digits for numeric labels. |
stars |
Significance-star policy. |
node_labels |
Optional named node labels. |
standalone |
Logical. Wrap in a standalone LaTeX document. |
theme |
Diagram theme. Use |
style |
Optional style overrides created by |
node_style |
Optional per-node style data frame or named list. Fields are
emitted as local TikZ node options, including |
edge_style |
Optional per-edge style data frame or named list. Fields are
emitted as local TikZ draw and label options, including |
routing |
Edge routing mode. |
escape |
Logical. Escape node labels and plain-text custom edge labels for LaTeX. Labels already written as LaTeX math or commands are preserved. |
file |
Output file path. |
compile |
Logical. Compile with a local TeX engine. |
engine |
TeX engine. |
clean |
Logical. Remove common TeX auxiliary files. |
... |
Passed to |
lvm_tikz() returns a character scalar. write_lvm_tikz()
invisibly returns the normalized output path.
lvmPlot() is the high-level entry point for the package. In an
interactive R session it asks whether to open the browser editor or draw a
static plot, with the editor offered first because it is the recommended path
for final manuscript figures. In non-interactive sessions it falls back to a
static plot so scripts, examples, and package checks never wait for input. Use
mode = "edit" to open the editor directly or mode = "plot" for a
static diagram.
edit_lvm() is a short alias for opening the interactive editor directly.
lvmPlot( object, ..., mode = c("ask", "edit", "plot"), label = c("auto", "std", "est", "both", "none"), digits = 2, stars = "auto", theme = lvm_theme_names(), style = NULL, export_name = "lvmPlot-diagram", launch = interactive() ) edit_lvm( object, ..., label = c("auto", "std", "est", "both", "none"), digits = 2, stars = "auto", theme = lvm_theme_names(), style = NULL, export_name = "lvmPlot-diagram", launch = interactive() )lvmPlot( object, ..., mode = c("ask", "edit", "plot"), label = c("auto", "std", "est", "both", "none"), digits = 2, stars = "auto", theme = lvm_theme_names(), style = NULL, export_name = "lvmPlot-diagram", launch = interactive() ) edit_lvm( object, ..., label = c("auto", "std", "est", "both", "none"), digits = 2, stars = "auto", theme = lvm_theme_names(), style = NULL, export_name = "lvmPlot-diagram", launch = interactive() )
object |
A supported latent variable model object or an |
... |
Arguments passed to |
mode |
Opening mode. |
label |
Edge label mode. |
digits |
Number of digits for edge labels. |
stars |
Significance-star policy. |
theme |
Plot theme. Use |
style |
Optional style overrides created by |
export_name |
Default file stem used by the editor downloads. |
launch |
Logical. If |
For mode = "plot", invisibly returns the plotted "lvm_graph".
For mode = "edit", returns the Shiny app object invisibly when launched
or visibly when launch = FALSE.
params <- data.frame( lhs = c("engage", "engage", "engage", "achieve"), op = c("=~", "=~", "=~", "~"), rhs = c("item1", "item2", "item3", "engage"), std.all = c(.78, .72, .69, .46), pvalue = c(.001, .001, .002, .004) ) graph <- lvmPlot(params, mode = "plot", label = "std") class(graph) if (requireNamespace("shiny", quietly = TRUE) && requireNamespace("jsonlite", quietly = TRUE)) { app <- lvmPlot(params, mode = "edit", label = "std", launch = FALSE) class(app) } if (interactive() && requireNamespace("shiny", quietly = TRUE) && requireNamespace("jsonlite", quietly = TRUE)) { lvmPlot(params, mode = "edit", label = "std") }params <- data.frame( lhs = c("engage", "engage", "engage", "achieve"), op = c("=~", "=~", "=~", "~"), rhs = c("item1", "item2", "item3", "engage"), std.all = c(.78, .72, .69, .46), pvalue = c(.001, .001, .002, .004) ) graph <- lvmPlot(params, mode = "plot", label = "std") class(graph) if (requireNamespace("shiny", quietly = TRUE) && requireNamespace("jsonlite", quietly = TRUE)) { app <- lvmPlot(params, mode = "edit", label = "std", launch = FALSE) class(app) } if (interactive() && requireNamespace("shiny", quietly = TRUE) && requireNamespace("jsonlite", quietly = TRUE)) { lvmPlot(params, mode = "edit", label = "std") }
lvmPlot_editor() opens a small Shiny application for final manual
adjustment of an automatically prepared LVM diagram. Nodes can be selected,
dragged, nudged with the keyboard, snapped to a grid, locked, aligned,
distributed, relabeled, repaired, undone/redone, and polished in the browser
preview. Coefficient labels can also be dragged for final manual placement, or
double-clicked to return them to automatic placement. Edge-label, theme,
preset, color, size, line-width, and font changes update the preview before
export; the edited coordinates, coefficient-label positions, node labels, and
style can then be exported as SVG/PDF/PNG, reusable R code, or a JSON editor
state that can be loaded later to continue editing.
lvmPlot_editor( object, ..., label = c("auto", "std", "est", "both", "none"), digits = 2, stars = "auto", theme = lvm_theme_names(), style = NULL, export_name = "lvmPlot-diagram", launch = interactive() )lvmPlot_editor( object, ..., label = c("auto", "std", "est", "both", "none"), digits = 2, stars = "auto", theme = lvm_theme_names(), style = NULL, export_name = "lvmPlot-diagram", launch = interactive() )
object |
A supported latent variable model object or an |
... |
Arguments passed to |
label |
Edge label mode used for preview and default export. |
digits |
Number of digits for edge labels. |
stars |
Significance-star policy. |
theme |
Initial plot theme for exported files. |
style |
Optional style overrides created by |
export_name |
Default file stem for downloaded artifacts. |
launch |
Logical. If |
A Shiny app object invisibly when launched, or visibly when launch = FALSE.
if (interactive() && requireNamespace("shiny", quietly = TRUE) && requireNamespace("jsonlite", quietly = TRUE)) { lvmPlot_editor( data.frame( lhs = c("f", "f", "y"), op = c("=~", "=~", "~"), rhs = c("x1", "x2", "f"), std.all = c(.7, .8, .4) ) ) }if (interactive() && requireNamespace("shiny", quietly = TRUE) && requireNamespace("jsonlite", quietly = TRUE)) { lvmPlot_editor( data.frame( lhs = c("f", "f", "y"), op = c("=~", "=~", "~"), rhs = c("x1", "x2", "f"), std.all = c(.7, .8, .4) ) ) }
These helpers are intended for RStudio Addins. Select an object name or an R expression that evaluates to a supported model, then run the addin to draw the diagram in the Plots pane or export TikZ code.
lvmPlot_rstudio_preview(object = NULL, ...) lvmPlot_rstudio_export_tikz(object = NULL, file = "lvmPlot-diagram.tex", ...)lvmPlot_rstudio_preview(object = NULL, ...) lvmPlot_rstudio_export_tikz(object = NULL, file = "lvmPlot-diagram.tex", ...)
object |
Optional object. When |
... |
Passed to |
file |
Output |
Invisibly returns the plotted graph or output file.
Draws latent variable model diagrams in the RStudio Plots pane and exports the same graph as SVG, PDF, or PNG.
plot_lvm(object, layout = NULL, layout_family = c("auto", "sem", "bifactor", "irt", "mixture", "growth", "multilevel", "circle"), orientation = c("top-down", "bottom-up", "left-right", "right-left"), diagram = c("auto", "all", "measurement", "structural", "loadings", "paths", "covariances", "compact"), show = NULL, min_abs = NULL, significant = NULL, alpha = 0.05, label = c("auto", "std", "est", "both", "none"), digits = 2, stars = "auto", node_labels = NULL, theme = lvm_theme_names(), style = NULL, node_style = NULL, edge_style = NULL, routing = c("straight", "smart", "none"), aspect = c("balanced", "preserve", "fill"), margin = 0.08, ...) ## S3 method for class 'lvm_graph' plot(x, ...) save_lvm_svg(object, file, width = "auto", height = "auto", ...) save_lvm_pdf(object, file, width = "auto", height = "auto", ...) save_lvm_png(object, file, width = "auto", height = "auto", res = 240, ...)plot_lvm(object, layout = NULL, layout_family = c("auto", "sem", "bifactor", "irt", "mixture", "growth", "multilevel", "circle"), orientation = c("top-down", "bottom-up", "left-right", "right-left"), diagram = c("auto", "all", "measurement", "structural", "loadings", "paths", "covariances", "compact"), show = NULL, min_abs = NULL, significant = NULL, alpha = 0.05, label = c("auto", "std", "est", "both", "none"), digits = 2, stars = "auto", node_labels = NULL, theme = lvm_theme_names(), style = NULL, node_style = NULL, edge_style = NULL, routing = c("straight", "smart", "none"), aspect = c("balanced", "preserve", "fill"), margin = 0.08, ...) ## S3 method for class 'lvm_graph' plot(x, ...) save_lvm_svg(object, file, width = "auto", height = "auto", ...) save_lvm_pdf(object, file, width = "auto", height = "auto", ...) save_lvm_png(object, file, width = "auto", height = "auto", res = 240, ...)
object |
A supported model object or |
layout |
Optional custom layout with |
layout_family |
Layout preset: automatic, SEM, bifactor, IRT, mixture, growth, multilevel, or circle. |
orientation |
Diagram direction. |
diagram |
Diagram preset used to filter edge types. |
show |
Optional explicit edge-type or diagram-type set to show. |
min_abs |
Optional minimum absolute estimate/standardized estimate. |
significant |
If |
alpha |
Significance threshold. |
label |
Edge label style: automatic, standardized estimates, raw
estimates, both, or no labels. |
digits |
Number of digits for numeric edge labels. |
stars |
Significance-star policy. |
node_labels |
Optional named node labels. |
theme |
Diagram theme. Use |
style |
Optional style overrides created by |
node_style |
Optional per-node style data frame or named list. Data-frame
columns can include |
edge_style |
Optional per-edge style data frame or named list. Data-frame
columns can include |
routing |
Edge routing mode. |
aspect |
Plot coordinate scaling. |
margin |
Outer plot margin. |
... |
Passed to |
x |
An |
file |
Output file path. |
width, height
|
Device size in inches, or |
res |
PNG output resolution in pixels per inch. |
plot_lvm() invisibly returns the graph. Save helpers invisibly return
the normalized output path.
params <- data.frame( lhs = c("f", "f", "y"), op = c("=~", "=~", "~"), rhs = c("x1", "x2", "f"), est = c(1, .8, .4) ) plot_lvm( params, layout = matrix(c(NA, "y", NA, NA, "f", NA, "x1", ".", "x2"), nrow = 3, byrow = TRUE), node_style = data.frame(name = "f", shape = "diamond", fill = "#EEF2FF"), edge_style = data.frame(from = "f", to = "y", label = "beta", linetype = "dashed", curvature = -.18) )params <- data.frame( lhs = c("f", "f", "y"), op = c("=~", "=~", "~"), rhs = c("x1", "x2", "f"), est = c(1, .8, .4) ) plot_lvm( params, layout = matrix(c(NA, "y", NA, NA, "f", NA, "x1", ".", "x2"), nrow = 3, byrow = TRUE), node_style = data.frame(name = "f", shape = "diamond", fill = "#EEF2FF"), edge_style = data.frame(from = "f", to = "y", label = "beta", linetype = "dashed", curvature = -.18) )
plot_sem() uses base R grid graphics, so a fitted lavaan model can be
previewed directly in the RStudio Plots pane. The save helpers write the same
diagram as SVG, PDF, or PNG.
plot_sem(object, layout = NULL, label = c("auto", "std", "est", "both", "none"), digits = 2, stars = "auto", residuals = FALSE, covariances = TRUE, node_labels = NULL, theme = lvm_theme_names(), style = NULL, node_style = NULL, edge_style = NULL, routing = c("straight", "smart", "none"), aspect = c("balanced", "preserve", "fill"), margin = 0.08, ...) ## S3 method for class 'sem_graph' plot(x, ...) save_sem_svg(object, file, width = 8, height = 4.8, ...) save_sem_pdf(object, file, width = 8, height = 4.8, ...) save_sem_png(object, file, width = 8, height = 4.8, res = 240, ...)plot_sem(object, layout = NULL, label = c("auto", "std", "est", "both", "none"), digits = 2, stars = "auto", residuals = FALSE, covariances = TRUE, node_labels = NULL, theme = lvm_theme_names(), style = NULL, node_style = NULL, edge_style = NULL, routing = c("straight", "smart", "none"), aspect = c("balanced", "preserve", "fill"), margin = 0.08, ...) ## S3 method for class 'sem_graph' plot(x, ...) save_sem_svg(object, file, width = 8, height = 4.8, ...) save_sem_pdf(object, file, width = 8, height = 4.8, ...) save_sem_png(object, file, width = 8, height = 4.8, res = 240, ...)
object |
A lavaan fit object, a lavaan-style parameter table, or an object
returned by |
layout |
Optional custom layout. See |
label |
Edge label style: automatic, standardized estimates, raw
estimates, both, or no labels. |
digits |
Number of digits for edge labels. |
stars |
Significance-star policy. |
residuals |
Logical. Draw variance self-loops. |
covariances |
Logical. Draw covariance paths. |
node_labels |
Optional named character vector, unnamed vector, or function used to relabel nodes. |
theme |
Diagram theme. Use |
style |
Optional style overrides created by |
node_style |
Optional per-node style data frame or named list. Columns can
include |
edge_style |
Optional per-edge style data frame or named list. Columns can
include |
routing |
Edge routing mode. |
aspect |
Plot coordinate scaling. |
margin |
Outer plot margin, in normalized parent coordinates. |
... |
Reserved for future extensions, or passed to |
x |
A |
file |
Output file path. |
width, height
|
Device size in inches. |
res |
PNG output resolution in pixels per inch. |
plot_sem() invisibly returns the "sem_graph" object used for
drawing. The save helpers invisibly return the normalized output path.
params <- data.frame( lhs = c("f", "f", "y"), op = c("=~", "=~", "~"), rhs = c("x1", "x2", "f"), est = c(1, .8, .4), std.all = c(.7, .6, .35), pvalue = c(NA, .001, .01) ) plot_sem(params)params <- data.frame( lhs = c("f", "f", "y"), op = c("=~", "=~", "~"), rhs = c("x1", "x2", "f"), est = c(1, .8, .4), std.all = c(.7, .6, .35), pvalue = c(NA, .001, .01) ) plot_sem(params)
select_lvm_layout() evaluates a grid of candidate layout settings and
chooses the candidate with the best layout_quality() score. It lets users
ask lvmPlot to try common orientation and routing alternatives before exporting
a figure.
select_lvm_layout(object, layout_family = "auto", orientation = c("top-down", "left-right", "bottom-up", "right-left"), diagram = "auto", routing = "straight", show = NULL, min_abs = NULL, significant = NULL, alpha = 0.05, label = c("auto", "std", "est", "both", "none"), digits = 2, stars = "auto", node_labels = NULL, node_style = NULL, edge_style = NULL, ...)select_lvm_layout(object, layout_family = "auto", orientation = c("top-down", "left-right", "bottom-up", "right-left"), diagram = "auto", routing = "straight", show = NULL, min_abs = NULL, significant = NULL, alpha = 0.05, label = c("auto", "std", "est", "both", "none"), digits = 2, stars = "auto", node_labels = NULL, node_style = NULL, edge_style = NULL, ...)
object |
A supported latent variable model object or |
layout_family |
Candidate layout families. |
orientation |
Candidate orientations. |
diagram |
Candidate diagram subsets. |
routing |
Candidate routing modes. |
show |
Optional edge types to show. |
min_abs |
Optional absolute loading/path threshold. |
significant |
Logical. Keep only significant estimated edges. |
alpha |
Significance threshold. |
label |
Edge label style used for scoring. |
digits |
Number of digits for edge labels. |
stars |
Significance-star policy. |
node_labels |
Optional node relabeling vector or function. |
node_style, edge_style
|
Optional per-node and per-edge style tables. |
... |
Passed to model adapters. |
A list with the selected graph, quality object, best candidate row, and
candidate table, with class "lvmPlot_layout_selection".
params <- data.frame( lhs = c("f", "f", "f"), op = "=~", rhs = c("x1", "x2", "x3"), std.all = c(.7, .8, .75) ) selection <- select_lvm_layout( params, orientation = c("top-down", "left-right"), label = "std" ) selection plot_lvm(selection$graph, label = "std")params <- data.frame( lhs = c("f", "f", "f"), op = "=~", rhs = c("x1", "x2", "x3"), std.all = c(.7, .8, .75) ) selection <- select_lvm_layout( params, orientation = c("top-down", "left-right"), label = "std" ) selection plot_lvm(selection$graph, label = "std")
sem_tikz() renders measurement paths, structural regressions, and
covariances from lavaan output as editable TikZ code.
sem_tikz(object, layout = NULL, label = c("auto", "std", "est", "both", "none"), digits = 2, stars = "auto", residuals = FALSE, covariances = TRUE, node_labels = NULL, standalone = FALSE, theme = lvm_theme_names(), style = NULL, node_style = NULL, edge_style = NULL, routing = c("straight", "smart", "none"), escape = TRUE, file = NULL, ...)sem_tikz(object, layout = NULL, label = c("auto", "std", "est", "both", "none"), digits = 2, stars = "auto", residuals = FALSE, covariances = TRUE, node_labels = NULL, standalone = FALSE, theme = lvm_theme_names(), style = NULL, node_style = NULL, edge_style = NULL, routing = c("straight", "smart", "none"), escape = TRUE, file = NULL, ...)
object |
A lavaan fit object, a lavaan-style parameter table, or an object
returned by |
layout |
Optional custom layout. See |
label |
Edge label style: automatic, standardized estimates, raw
estimates, both, or no labels. |
digits |
Number of digits for edge labels. |
stars |
Significance-star policy. |
residuals |
Logical. Draw variance self-loops. |
covariances |
Logical. Draw covariance paths. |
node_labels |
Optional named character vector, unnamed vector, or function used to relabel nodes. |
standalone |
Logical. Wrap the TikZ picture in a standalone LaTeX document. |
theme |
Diagram theme. Use |
style |
Optional style overrides created by |
node_style |
Optional per-node style data frame or named list. The same
node style fields used by |
edge_style |
Optional per-edge style data frame or named list. The same
edge style fields used by |
routing |
Edge routing mode. |
escape |
Logical. Escape node labels and plain-text custom edge labels for LaTeX. Labels already written as LaTeX math or commands are preserved. |
file |
Optional path to write the generated code. |
... |
Reserved for future extensions. |
A character scalar with class "sem_tikz".
params <- data.frame( lhs = c("f", "f", "y"), op = c("=~", "=~", "~"), rhs = c("x1", "x2", "f"), est = c(1, .8, .4), std.all = c(.7, .6, .35), pvalue = c(NA, .001, .01) ) sem_tikz(params)params <- data.frame( lhs = c("f", "f", "y"), op = c("=~", "=~", "~"), rhs = c("x1", "x2", "f"), est = c(1, .8, .4), std.all = c(.7, .6, .35), pvalue = c(NA, .001, .01) ) sem_tikz(params)
write_sem_tikz() writes a TikZ path diagram to a .tex file and can
optionally compile it when a local TeX engine is available.
write_sem_tikz(object, file, standalone = TRUE, compile = FALSE, engine = c("pdflatex", "xelatex", "lualatex", "tectonic"), clean = TRUE, ...)write_sem_tikz(object, file, standalone = TRUE, compile = FALSE, engine = c("pdflatex", "xelatex", "lualatex", "tectonic"), clean = TRUE, ...)
object |
A lavaan fit object, lavaan-style parameter table,
|
file |
Output |
standalone |
Logical. If |
compile |
Logical. Compile the |
engine |
TeX engine used when |
clean |
Logical. Remove common TeX auxiliary files after successful compilation. |
... |
Passed to |
Invisibly returns the normalized output path.