【问题标题】:In Graphviz, how to set only one edge to spline=curve在 Graphviz 中,如何仅将一条边设置为 spline=curve
【发布时间】:2020-10-09 11:06:34
【问题描述】:

我正在尝试使用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 图

【问题讨论】:

    标签: r graphviz dot


    【解决方案1】:

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

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

    然后你可以用

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

    您还需要graph 选项splines=true

    添加这些产品

    【讨论】:

    • 谢谢您的回答;优雅、富有创意且解释清楚。完美解决了我的问题。
    • 不客气。如果它也适合您的用例,对于这些小图,我通常会转到 tikz / dot2tex,因为我发现它更容易进行精细控制。
    猜你喜欢
    • 2013-03-02
    • 2017-04-05
    • 1970-01-01
    • 1970-01-01
    • 2010-12-01
    • 2015-01-01
    • 2010-11-21
    • 1970-01-01
    • 2023-03-22
    相关资源
    最近更新 更多