首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在semPlot中具有自定义布局的弯曲向量箭头

在semPlot中具有自定义布局的弯曲向量箭头
EN

Stack Overflow用户
提问于 2019-11-09 05:07:05
回答 1查看 196关注 0票数 0

我刚开始使用semPlots,但我找到了一种使用自定义布局sempathmatrix以我想要的方式组织变量的方法。变量的布局很好,可能需要一些轻微的调整,但我希望向量是弯曲的。使用曲线、曲率或其他与曲线相关的参数不会对自定义布局执行任何操作。

关于如何使用自定义布局在这个semplot中获得曲线矢量有什么想法吗?

我尝试添加curvecurvaturecurveAdjacent参数,但都没有对我的sempathmatrix布局造成影响。如果我切换回树或tree2,曲线就会显示出来。似乎找不到答案。

代码语言:javascript
复制
########Creating the Manual Lables and Layout Matrix for Cope Model Plot 

lbls<-c("Depression","Flourishing","Active\nCoping","Beh\nDisengage","Self\nCompassion","Self\nColdness")

sempathmatrix<-matrix(c(.5,.5, .5,-.5, 0,.4, 0,-.4, -.5,.5, -.5,-.5, .5,.5, .5,-.5), ncol=2,byrow=T)

####Path analysis Plot for Coping Model ######

semPaths(fit, "std", residuals = F, intercepts = F, layout = sempathmatrix, fade=F, rotation = 3, nCharNodes= 0, nodeLabels=lbls, edge.label.cex=0.7, freeStyle = T, title=F, sizeMan = 9, mar = c(5,5,5,5))

SemPlot:

EN

回答 1

Stack Overflow用户

发布于 2020-07-14 16:53:49

您可以在创建和保存semPaths plot之后操作曲线。如果将绘图另存为p,则可以使用p$graphAttributes$Edges$curve访问控制曲线的矢量。然后,您可以将该向量中的值替换为新的向量,该向量由0到1之间的值组成,并具有所需的曲率级别。您还可以通过向semPaths调用添加edgeLabels = 1:n (其中n是边数)来找到边在向量中的位置。这将有助于创建矢量,以便以首选方式控制曲率。

以下是该过程的可重复示例。

代码语言:javascript
复制
# Open the packages (install them first if you haven't yet)
library(lavaan)
library(semPlot)

# Generate data

df <- data.frame(replicate(3, rnorm(100, 0, 1)))

# Create SEM-model

model <- "
X1 ~ X2
X1 ~ X3
X2 ~ X3"

fit <- sem(model, df)

# Custom layout

x <- c(-1, -1, 1)
y <- c(-1, 1, 0)
m <- matrix(c(x,y), ncol = 2)

# Add identifier to edges to find out their position later

semPaths(fit, layout = m, edgeLabels = 1:6, edge.label.cex = 2)

# We can add curvature if we save the plot and manipulate metadata

p <- semPaths(fit, layout = m)

# This command yields access to control the curve
p$graphAttributes$Edges$curve

# By replacing this vector, we add curve to our plot
p$graphAttributes$Edges$curve <- c(0.9, 0.2, 0.5, 0, 0, 0)

# Then we can plot manipulated p with plot()-function and see the curvature
plot(p)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58773809

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档