r - 是否可以更改 semPaths 中箭头的长度/位置?
问题描述
我正在尝试使用 semPlot::semPaths 绘制我在 lavaan 中运行的双因子模型的图。semPlot 和 qgraph 的文档真的很棒,所以我已经能够弄清楚我想要的大部分规范,但有一件事我不确定是否可以修复。正如您在下图中所见,当潜在因素(例如,“ext”)连接到广泛的清单变量时,很难跟踪哪些箭头/标签与哪些清单变量相关联。(例如,很难判断 adhd3 的 ext 加载是 0.23。)看起来箭头试图连接到清单变量标签的中心,而不是最近的一侧。有什么办法可以改变它,让它更容易阅读吗?太感谢了!
这是我使用的代码(抱歉,它很笨拙——1)我是新手,2)潜在变量自动出现在奇怪的地方,所以我手动定义了它们的位置):
full_bif_mod <- "ext =~ cd1 + cd2 + cd3 + cd4 + cd5 + cd6 + cd7 + cd8 + cd9 + cd10 + cd11 + cd12 + cd13 + cd14 + cd15 + cd16 + cd17 + aud1 + aud2 + aud3 + aud4 + aud5 + aud6 + aud7 + aud8 + aud9 + aud10 + adhd1 + adhd2 + adhd3
cd =~ cd1 + cd2 + cd3 + cd4 + cd5 + cd6 + cd7 + cd8 + cd9 + cd10 + cd11 + cd12 + cd13 + cd14 + cd15 + cd16 + cd17
aud =~ aud1 + aud2 + aud3 + aud4 + aud5 + aud6 + aud7 + aud8 + aud9 + aud10
adhd =~ adhd1 + adhd2 + adhd3
ext ~~ 0*adhd
ext ~~ 0*cd
ext ~~ 0*aud
adhd ~~ 0*cd
adhd ~~ 0*aud
cd ~~ 0*aud
"
summary((full_bifactor <- cfa(full_bif_mod, std.lv=TRUE, data=dat)),fit.measures=TRUE, standardized = T)
x=c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30, 15, 9, 22, 29)
y=c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,-1,-1,-1)
ly=matrix(c(y,x), ncol=2)
semPaths(full_bifactor, layout=ly, whatLabels="std", style="lisrel", nCharNodes=5, exoCov=FALSE, residuals=FALSE, label.scale=TRUE, sizeMan2=1.5, sizeMan=6, asize=1, edge.color="black", edge.label.color="black", edge.label.position=.8, edge.label.margin=-.1, width=17, height=20, filetype="png",filename="cfa"
)
解决方案
这可以使用 qgraph 中的边缘连接点来完成!见下文:
# Save plot to object:
Plot <- semPaths(full_bifactor, layout=ly,
whatLabels="std", style="lisrel", nCharNodes=5,
exoCov=FALSE, residuals=FALSE, label.scale=TRUE,
sizeMan2=1.5, sizeMan=6, asize=1, edge.color="black",
edge.label.color="black", edge.label.position=.8, edge.label.margin=-.1,
width=17, height=20, filetype="png",filename="cfa"
)
# Add edge connect point to end point of edges (2nd column) for bifactor:
Plot$graphAttributes$Edges$edgeConnectPoints[1:30,2] <- 0.5 * pi
# Add edge connect point to end point of edges (2nd column) for other factors:
Plot$graphAttributes$Edges$edgeConnectPoints[31:60,2] <- 1.5 * pi
# Plot again:
library("qgraph")
plot(Plot)
推荐阅读
- python - 当我尝试将脚本打包到 .exe 时,Python 没有模块名称导入
- javascript - 在Javascript中区分两个对象数组
- icons - PhpStorm 版本 2020.1:文件图标符号上的点的含义
- windows - 如何将文件复制到带有通配符的Windows路径?
- progressive-web-apps - 使用 next-pwa 编译 NextJs 时出错 - web loader
- algorithm - O(n^2) 中的 Knuth 最优二叉搜索树
- python - Jupyter 笔记本中的错误“IndentationError:预期有缩进块”
- python - 为什么按下我的 tkinter python 时钟的按钮时会有空格
- java - 如何使用 SimpleJdbcCall 同步调用存储过程
- java - Cannot resolve symbol "Base64" while importing apache commons codec