| Title: | Graphical User Interface with Integrated 'Diagrammer' for 'Lavaan' |
|---|---|
| Description: | Provides a graphical user interface with an integrated diagrammer for latent variable models from the 'lavaan' package. It offers two core functions: first, lavaangui() launches a web application that allows users to specify models by drawing path diagrams, fitting them, assessing model fit, and more; second, plot_lavaan() creates interactive path diagrams from models specified in 'lavaan'. After customizing a diagram interactively, export_plot() saves it to a file, enabling reproducible scripts without sacrificing fine-grained control over appearance. Karch (2024) <doi: 10.1080/10705511.2024.2420678> contains a tutorial. |
| Authors: | Julian D. Karch [aut, cre, cph] (ORCID: <https://orcid.org/0000-0002-1625-2822>) |
| Maintainer: | Julian D. Karch <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.4.0.9000 |
| Built: | 2026-05-14 09:23:31 UTC |
| Source: | https://github.com/karchjd/lavaangui |
Renders the path diagram for a lavaan model and saves it directly to a file without requiring manual interaction.
export_plot(fit, filename, layout = "default", scale = 1)export_plot(fit, filename, layout = "default", scale = 1)
fit |
A lavaan model, as returned by the |
filename |
A single character string giving the output file path.
The file extension determines the format: |
layout |
A character string specifying the name of a previously saved layout to use
(default: |
scale |
A positive number controlling the output resolution relative to screen size
(default: |
nothing
plot_lavaan() to create and interactively edit path diagrams,
remove_layouts() to delete saved layouts.
library(lavaan) model <- " visual =~ x1 + loadingx2*x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 " fit <- cfa(model, data = HolzingerSwineford1939) # First run plot_lavaan to interactively arrange the diagram and save a layout, # then export it non-interactively: plot_lavaan(fit) export_plot(fit, "diagram.png") export_plot(fit, "diagram.pdf", scale = 2)library(lavaan) model <- " visual =~ x1 + loadingx2*x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 " fit <- cfa(model, data = HolzingerSwineford1939) # First run plot_lavaan to interactively arrange the diagram and save a layout, # then export it non-interactively: plot_lavaan(fit) export_plot(fit, "diagram.png") export_plot(fit, "diagram.pdf", scale = 2)
The lavaangui function launches the lavaangui Shiny application.
lavaangui(fit = NULL)lavaangui(fit = NULL)
fit |
A lavaan model, as returned by the |
Currently, multiple-group models are not supported. However, you can create an
interactive plot of those models using plot_lavaan
nothing
# Without importing lavaan model lavaangui() # Importing a lavaan model library(lavaan) model <- " visual =~ x1 + loadingx2*x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 " fit <- cfa(model, data = HolzingerSwineford1939) lavaangui(fit)# Without importing lavaan model lavaangui() # Importing a lavaan model library(lavaan) model <- " visual =~ x1 + loadingx2*x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 " fit <- cfa(model, data = HolzingerSwineford1939) lavaangui(fit)
The plot_lavaan function creates path diagrams for lavaan model.
The created paths diagrams are interactive.
That is, their appearance can be customized easily, for example, by dragging
around nodes representing variable with the mouse.
plot_lavaan(fit, layout = "default", where = "gadget")plot_lavaan(fit, layout = "default", where = "gadget")
fit |
A lavaan model, as returned by the |
layout |
A character string specifying the name of the layout to use (default: |
where |
A character string to specify where the path diagram should be shown. The default value "gadget" shows it directly in Rstudio. For "browser", it's shown in your default browser. For non-RStudio users, the parameter has no effect, and the path diagram is always shown in the browser. |
When layout is not NULL, closing the interactive diagram saves the
current graph state — including node positions and display settings
(e.g., which estimates or confidence intervals are shown) — as a layout
file in the working directory. This layout is automatically restored
the next time you call plot_lavaan with the same model, so that you do not
have to rearrange the diagram each time. Saved layouts are also used by
export_plot() to export the diagram to a file non-interactively, making
it easy to reproduce publication-ready figures from R scripts.
nothing
export_plot() to export diagrams to a file without interaction,
remove_layouts() to delete saved layouts.
library(lavaan) model <- " visual =~ x1 + loadingx2*x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 " fit <- cfa(model, data = HolzingerSwineford1939) plot_lavaan(fit) # After arranging the diagram interactively, export it to a file: export_plot(fit, "my_diagram.png")library(lavaan) model <- " visual =~ x1 + loadingx2*x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 " fit <- cfa(model, data = HolzingerSwineford1939) plot_lavaan(fit) # After arranging the diagram interactively, export it to a file: export_plot(fit, "my_diagram.png")
Removes layout files previously saved by plot_lavaan() for a given lavaan model.
remove_layouts(fit, layout = NULL)remove_layouts(fit, layout = NULL)
fit |
A lavaan model, as returned by the |
layout |
A character string specifying which layout to remove.
If |
Invisibly returns the paths of removed files.
plot_lavaan() to create and interactively edit path diagrams,
export_plot() to export diagrams to a file without interaction.
library(lavaan) model <- " visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 " fit <- cfa(model, data = HolzingerSwineford1939) remove_layouts(fit)library(lavaan) model <- " visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 " fit <- cfa(model, data = HolzingerSwineford1939) remove_layouts(fit)