simsem / semTools

Useful tools for structural equation modeling
75 stars 36 forks source link

plotProbe with no legend #28

Closed maugavilla closed 6 years ago

maugavilla commented 6 years ago

Add an argument to the plotProbe function to plot without a legend, so we can plot the Johnson-Neyman tests, something like this

library(lavaan) 
library(semTools)

dat2wayMC <- indProd(dat2way, 1:3, 4:6)

model1 <- "
f1 =~ x1 + x2 + x3
f2 =~ x4 + x5 + x6
f12 =~ x1.x4 + x2.x5 + x3.x6
f3 =~ x7 + x8 + x9
f3 ~ f1 + f2 + f12
f12 ~~0*f1
f12 ~~ 0*f2
x1 ~ 0*1
x4 ~ 0*1
x1.x4 ~ 0*1
x7 ~ 0*1
f1 ~ NA*1
f2 ~ NA*1
f12 ~ NA*1
f3 ~ NA*1
"

fitMC2way <- sem(model1, data = dat2wayMC, std.lv = FALSE,
                 meanstructure = TRUE)
summary(fitMC2way)

result2wayMC <- probe2WayMC(fitMC2way, c("f1", "f2", "f12"),
                            "f3", "f2", seq(from=-3,to=3,by=.1))
result2wayMC

plotProbe(result2wayMC, xlim = c(-2, 2))
TDJorgensen commented 6 years ago

I added this feature. There is a legend=TRUE argument that can be set FALSE to suppress a legend. There is also a legendArgs = list() argument, so you can pass arguments to the legend() function. Using your example above, see how these arguments work:

plotProbe(result2wayMC, xlim = c(-2, 2), legend = FALSE)
plotProbe(result2wayMC, xlim = c(-2, 2), legendArgs = list(x = "topleft"))
plotProbe(result2wayMC, xlim = c(-2, 2), legendArgs = list(x = -2, y = 5))