alishinski / lavaanPlot

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

conditional formatting based on significance and sign #46

Open mluerig opened 1 year ago

mluerig commented 1 year ago

hey, great package! I'm giving the lavaanPlot2function a try, and I'd like to color edges based on whether the effect is significantly positive or negative, and if neither, gray. is there a way to do this?

EDIT: also, right now, turnin off plotting non-significant estimates is not working? (sig argument)

alishinski commented 4 months ago

I've got an initial version of this working https://github.com/alishinski/lavaanPlot/tree/dir, give it a spin.

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

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

c_opts <- formatting(list(color = "yellow", penwidth = 3), list(color = "blue", penwidth = 3), type = "dir")

lavaanPlot2(fit,
            graph_options = list(label = "my first graph with signficance stars"),
            edge_options = c_opts)

Regressions: Estimate Std.Err z-value mpg ~
cyl -0.987 0.738 -1.337 disp -0.021 0.010 -2.178 hp -0.017 0.014 -1.218 qsec ~
disp -0.008 0.004 -2.122 hp -0.023 0.004 -5.229 wt 1.695 0.398 4.256

direction_format

mluerig commented 4 months ago

this is cool, works like a charm!

one small additional request / question: can we choose to (not) color an edge because it is not significant? e.g., have it in black

also, unrelated: can we control the size of the edge based on its effect size?