alishinski / lavaanPlot

R package for plotting lavaan path models with DiagrammeR
http://alexlishinski.com/lavaanPlot/
38 stars 4 forks source link

Hide arrows for insignificant paths (not only the coefficient) #27

Closed Buedenbender closed 2 years ago

Buedenbender commented 3 years ago

Is it possible to hide the arrows of non-significant paths? Not only the path coefficients? I know that one can specify significance level (e.g. sig = .05) and consequently the non-significant coefficients (path-weights) are omitted, however it would really improve readability for bigger models if it would be possible to also omit the arrow.

Minimal Reproducibel Example

#Github MRE for hiding insignificant paths
library(lavaanPlot)

model <- 'mpg ~ cyl + disp + hp
          qsec ~ disp + hp + wt'

fit <- sem(model, data = mtcars)
summary(fit)

lavaanPlot(model = fit, 
           node_options = list(shape = "box", fontname = "Helvetica"), 
           edge_options = list(color = "grey"), 
           coefs = TRUE,
           stand = TRUE,
           # covs = TRUE,
           sig = .05,
           stars = "regress")
alishinski commented 3 years ago

It's not possible right now, but it could definitely be added, I'll put it on the to do list. In the meantime, if you need to modify a lavaanPlot diagram to omit some paths, you can always manually modify the diagram specification and get rid of paths you don't want. E.g.:

model <- " wt ~~ disp
  mpg ~ cyl + disp + hp
  qsec ~ disp + hp + wt"

fit <- sem(model, data = mtcars)
plo <- lavaanPlot(model = fit, coefs = TRUE, stand = TRUE, covs = TRUE)

# gives you the diagram specification
plo$x$diagram

# modify that and put into this function
grViz()