Closed libbybenson3 closed 6 years ago
You can tweak things after plotting manually using qgraph. Do the codes below do what you want?
Graph <- semPaths(model_fit, what = "model", "est",
sizeLat = 6, sizeMan = 6, sizeInt = 5,
edge.label.cex = 1, layout = newlayout,
edge.label.position = newedges,
curvePivot = TRUE)
# Extract some info:
Edgelist <- as.data.frame(Graph$Edgelist)
Labels <- Graph$graphAttributes$Nodes$labels
# Make curve object:
Curve <- rep(0, nrow(Edgelist))
# Make some edges curved:
Curve[Edgelist$from == which(Labels == "y12") & Edgelist$to == which(Labels == "y11")] <- Curve[Edgelist$from == which(Labels == "y11") & Edgelist$to == which(Labels == "y12")] <- 1
Curve[Edgelist$from == which(Labels == "y21") & Edgelist$to == which(Labels == "y22")] <- Curve[Edgelist$from == which(Labels == "y22") & Edgelist$to == which(Labels == "y21")] <- 1
Curve[Edgelist$from == which(Labels == "y31") & Edgelist$to == which(Labels == "y32")] <- Curve[Edgelist$from == which(Labels == "y32") & Edgelist$to == which(Labels == "y31")] <- -1
Curve[Edgelist$from == which(Labels == "y41") & Edgelist$to == which(Labels == "y42")] <- Curve[Edgelist$from == which(Labels == "y42") & Edgelist$to == which(Labels == "y41")] <- -1
# Now the loopRotation object to fix the rotation:
loopRotation <- Graph$graphAttributes$Nodes$loopRotation
loopRotation[Labels == "y31"] <- pi
loopRotation[Labels == "y42"] <- pi
loopRotation[Labels == "y11"] <- 0
loopRotation[Labels == "y21"] <- 0
loopRotation[Labels == "y22"] <- 0
library(qgraph)
qgraph(Graph, curve = Curve, loopRotation = loopRotation)
Hi Sacha, Yes! Your code answers/ solves both of my questions - thank you :)
Thank you for the awesome work that went into the creation of the semPlot package and semPaths() - I use it all the time for my own work and for teaching purposes :)
I am assisting a professor with creating teaching materials for a longitudinal structural equation modeling class, and have ran into a few snags.
For example, I am working on cleaning up a cross-lagged model plot. The first two steps I took were to specify a custom layout for the latent and manifest variables, and then to clean up the paths with overlapping values.
Question 1: I then wanted to add curved lines for the autocorrelated errors using the curvePivot argument, but it seems that this argument does not work when a custom layout is specified.
Question 2: I also wanted to try to move some of the residual variance double headed arrows, but couldn't figure out how to do this based on the documentation.
Below, I have included a data generation method, the model I am fitting, and the different plot iterations I went through. Any advice on how to solve question 1 and/or question 2 would be greatly appreciated. Thank you! Libby