在 Graphviz 中,如何将一条边设置为 spline=curve

In Graphviz, how to set only one edge to spline=curve

我正在尝试使用 Graphviz 绘制一个 lavaan 模型并且总体上对它的外观感到满意(第一个图),但希望两个维度之间的边缘是弯曲的但是所有其他人都是直的。

是否可以通过指定 graph [layout = neato, overlap = FALSE, outputorder = edgesfirst, splines = curved] 使尺寸之间的边(边 d1d2)弯曲,如第二张图所示,但这使得都是弧形的。

谁能指导我如何得到想要的结果?

这是重现第一张图的代码:

grViz("
digraph CFA {
graph [layout = neato, overlap = FALSE, outputorder = edgesfirst]
node [shape = rectangle]
edge [arrowhead = vee]
# Nodes (variables)
m1 [pos = '-5,1.5!', label = 'VAR1']
m2 [pos = '-5,0.5!', label = 'VAR2']
m3 [pos = '-5,-0.5!', label = 'VAR3']
m4 [pos = '-5,-1.5!', label = 'VAR4']
d1 [pos = '-1.5,0!', label = 'Info', shape = ellipse, width=1]
d2 [pos = '1.5,0!', label = 'Support', shape = ellipse, width=1]
m5 [pos = '5,1.5!', label = 'VAR5']
m6 [pos = '5,0.5!', label = 'VAR6']
m7 [pos = '5,-0.5!', label = 'VAR7']
m8 [pos = '5,-1.5!', label = 'VAR8']
# Edges (loadings)
d1->m1 [label = '1']
d1->m2 [label = '0.82']
d1->m3 [label = '1.20']
d1->m4 [label = '0.70']
d2->m5 [label = '1']
d2->m6 [label = '0.89']
d2->m7 [label = '1.08']
d2->m8 [label = '1.15']
# Define Error
m1->m1 [label = '0.34', dir=both, tailport = 'sw', headport = 'nw', arrowhead=curve, arrowtail=curve, style=dashed]
m2->m2 [label = '0.45', dir=both, tailport = 'sw', headport = 'nw', arrowhead=curve, arrowtail=curve, style=dashed]
m3->m3 [label = '0.28', dir=both, tailport = 'sw', headport = 'nw', arrowhead=curve, arrowtail=curve, style=dashed]
m4->m4 [label = '0.98', dir=both, tailport = 'sw', headport = 'nw', arrowhead=curve, arrowtail=curve, style=dashed]
m5->m5 [label = '0.64', dir=both, tailport = 'se', headport = 'ne', arrowhead=curve, arrowtail=curve, style=dashed]
m6->m6 [label = '0.31', dir=both, tailport = 'se', headport = 'ne', arrowhead=curve, arrowtail=curve, style=dashed]
m7->m7 [label = '0.42', dir=both, tailport = 'se', headport = 'ne', arrowhead=curve, arrowtail=curve, style=dashed]
m8->m8 [label = '0.25', dir=both, tailport = 'se', headport = 'ne', arrowhead=curve, arrowtail=curve, style=dashed]
d1->d1 [label = '0.65', dir=both, tailport = 'se', headport = 'ne', arrowhead=curve, arrowtail=curve, style=dashed]
d2->d2 [label = '0.72', dir=both, tailport = 'sw', headport = 'nw', arrowhead=curve, arrowtail=curve, style=dashed]
# Covariance
d1->d2 [label = '0.45', dir = both, arrowhead=vee, arrowtail=vee, splines=curved, tailport = 's', headport = 's']
}
")

情节如下:

第一个所有边都是直的 CFA 图

具有弯曲边缘的第二个 CFA 图

一种方法是使用虚拟节点,我们将尝试围绕它弯曲边缘(更改 height 以控制曲线)

dummy [pos = '0,0!', height=1.5, label='', color=white]

然后你可以用

设置相关性/曲线边缘
d1:s->d2:s [label = '0.45', dir = both]

您还需要 graph 选项 splines=true

添加这些产品