WYSIWYG path diagrams in R

3 views
Skip to first unread message

Phil Wood

unread,
Feb 13, 2026, 5:26:43 PM (9 days ago) Feb 13
to Structural Equation Modeling
Many thanks to you all for visiting the website for the book which came out this year (https://sites.google.com/view/understanding-structural-equa/home
Hi all, As some of you may have discovered, the lavaan gui for WYSIWYG path diagrams is no more. This leaves you with two options: Onyx, which is free, and SPSS' Amos, which is not. Although it's always an option to install Onyx on your machine and draw the diagram yourself, that's a bit silly if you have already written the lavaan code for it. Fortunately, it's also an option to from a lavaan solution to an Onyx diagram. You'll have to provide R an address for where the Onyx program is (in this example it's on my desktop) and install the remotes package, but from there it works fairly well. Here's an example of the code:
Let me know if you have any questions. Phil
========================code begins here==================

#install.packages("remotes")

library(lavaan)
library(onyxR)
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))

ModelData <- 
  read.table("widmantryingdontmindlast30days.txt", header = TRUE) ;
RegModel <- "
  Lst30Dys ~ B*DontMind + A*Trying

  Lst30Dys ~~ E*Lst30Dys
  DontMind ~~ VD*DontMind
  Trying ~~ VT*Trying
  DontMind ~~ CTD*Trying

  Lst30Dys ~ I*1
  Trying ~ MT*1
  DontMind ~ MD*1
"

fit <- sem(RegModel, data = ModelData, meanstructure = TRUE)

library(onyxR)

jar <- normalizePath(
  "C:/Users/woodph/OneDrive - University of Missouri/Desktop/onyx-1.0-1040.jar",
  winslash = "/"
)

onyx(model = fit, onyxfile = jar)
library(onyxR)

jar <- utils::shortPathName("C:/Users/woodph/OneDrive - University of Missouri/Desktop/onyx-1.0-1040.jar")
java <- utils::shortPathName(Sys.which("java"))
java_path <- dirname(java)


onyx(model = fit, onyxfile = jar, java_path = java_path)

Reply all
Reply to author
Forward
0 new messages