将节点连接到其他两个节点之间的边缘

时间:2019-04-10 15:41:39

标签: r diagrammer

我目前正在尝试使用DiagrammeR创建流程图

library(DiagrammeR)
grViz("
digraph g { 
subgraph cluster_0 {
style=filled;
color=lightgrey;
label= To_Accrue
node [shape = rectangle, style = filled, fillcolor = Linen]
A
B
C
A->B->C
}
subgraph cluster_1 {
style=filled;
color=crimson;
label= Y
node [style=filled,color=blue, shape=folder]
1
2
3
1->2->3
}
}
")

请参考链接File以查看其当前生成的内容(Tab-Sheet1)。我想知道是否有一种方法可以达到所需的输出(制表期望的输出)。

谢谢。

2 个答案:

答案 0 :(得分:0)

这里的技巧是使用一个空白节点(此处称为bnode),组(在此示例中为g1)和排名(rank=same ...)来强制您定位和显示想。具有相同组的节点应该出现在相同的垂直平面中,具有相同等级的节点应该出现在相同的水平面中。

library(DiagrammeR)

grViz("
digraph g { 
subgraph cluster_0 {
style=filled;
color=lightgrey;
label= To_Accrue
node [shape = rectangle, style = filled, fillcolor = Linen]
bnode [style = invis, shape=point, width = 0, group=g1]
A [group=g1]
B
C [group=g1]
edge [arrowhead='none']
A->bnode
edge [arrowhead='normal']
B->bnode
bnode->C
{rank=same B bnode}
}
subgraph cluster_1 {
style=filled;
color=crimson;
label= Y
node [style=filled,color=blue, shape=folder]
1
2
3
1->2->3
}
}
")

答案 1 :(得分:0)

我还编辑了原始代码,以生成以下内容以应对轮换情况。 enter image description here

library(DiagrammeR)

grViz("
digraph g { 
subgraph cluster_0 {
style=filled;
color=lightgrey;
label= To_Accrue
node [shape = rectangle, style = filled, fillcolor = Linen]
a1 [style = invis, shape=point, width = 0, group=g1]
a2 [style = invis, shape=point, width = 0, group=g2]
a3 [style = invis, shape=point, width = 0, group=g3]
A [group=g1]
B
C [group=g1]
C [group=g2]
D
E [group=g2]
edge [arrowhead='none']
A->a1
C->a2
E->a3
edge [arrowhead='normal']
B->a1 {rank=same B a1}
a1->C
D->a2 {rank=same D a2}
a2->E
F->a3 {rank=same F a3}
a3->G
}
subgraph cluster_1 {
style=filled;
color=crimson;
label= Y
node [style=filled,color=blue, shape=folder]
1
2
3
1->2->3
}
}
")