【问题标题】:Graphviz: Edge orientation to and from same nodeGraphviz:到和来自同一节点的边缘方向
【发布时间】:2020-07-10 08:29:04
【问题描述】:

我正在创建一些多级 SEM 图,但遇到了一个小问题。图底部的潜在变量(标记为“WF”)应该具有往返于它的双头边,但边应该位于节点下方。注意最顶层节点的正确方向。似乎很容易修复,但我可以找到它。提前致谢。 (顺便说一句,我只提供了原始模型的 sn-p,但这已经足够了。)

digraph stackex {

    {rank=min;
    bf [shape=ellipse]
    bf:nw -> bf:ne [dir = both]}

    {node[shape=square]
      bf -> i1 
      i1[label=X1]
      i1 -> wf [dir=back]}

    {wf [shape=ellipse]
    wf:sw -> wf:se [dir = both]}
}

这是它产生的结果:

双头箭头应位于标有“WF”的节点下方。

【问题讨论】:

    标签: graphviz edges arrows


    【解决方案1】:

    根据实验,似乎只有这样才能获得

    wf:sw -> wf:se [dir = both]
    

    做你想做的就是添加

    graph [rankdir=TB]
    

    不幸的是,rankdir 会影响整个图(不仅仅是子图或集群)。所以你可以修复一个循环,但你会破坏另一个循环。
    我发现实现您的目标的唯一方法是手动修改违规边缘(样条)的 pos。这个:

    digraph stackex {
        graph [bb="0,0,82.583,216"];
        node [label="\N",
            shape=square
        ];
        bf  [height=0.5,
            pos="41.292,162",
            shape=ellipse,
            width=0.75];
        bf:nw -> bf:ne  [dir=both,
            pos="s,26.292,177 e,56.292,177 22.277,186.17 18.135,200.16 21.792,216 41.292,216 60.792,216 64.448,200.16 60.306,186.17"];
        i1  [height=0.5,
            label=X1,
            pos="41.292,90",
            width=0.5];
        bf -> i1    [pos="e,41.292,108.1 41.292,143.7 41.292,135.98 41.292,126.71 41.292,118.11"];
        wf  [height=0.5,
            pos="41.292,18",
            shape=ellipse,
            width=0.75];
        i1 -> wf    [dir=back,
            pos="s,41.292,71.697 41.292,61.665 41.292,53.054 41.292,43.791 41.292,36.104"];
        wf:se -> wf:sw  [dir=both,
            pos="s,56.292,3 e,26.292,3 
    65.002,8.3185 
    92.908,0.389 
    88.823,-20 
    41.292,-20 
    -6.2395,-20 
    -10.324,0.389 
    17.582,8.3185"];
    }
    

    还有这个命令 neato -n2 -Tpng doubleheaded3.fixed.dot >doubleheaded3.fixed.png 给出了这个:

    总而言之,我建议使用 pic/gpic/dpic 语言。级别较低,但从长远来看可能更易于使用。

    【讨论】:

    • 谢谢!我敢肯定,该解决方案需要相当多的努力。我会研究 gpic,但 graphviz 的好处是它(大部分)通过“diagrammeR”包在 R 和 Rmarkdown 中工作得很好。
    猜你喜欢
    • 1970-01-01
    • 2017-12-19
    • 2012-10-10
    • 1970-01-01
    • 2013-07-13
    • 2012-07-02
    • 2011-05-14
    • 2020-07-23
    • 2020-02-19
    相关资源
    最近更新 更多