I am currently trying to create a flowchart using 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
}
}
")
Please refer to the link File to see what it currently generates (Tab-Sheet1). I was wondering if there is a way to achieve the desired output (Tab-Desired Output).
Thank you in advance.
The trick here is to use a blank node (called bnode
here), groups (g1
in this example), and ranks (rank=same ...
) to force the positioning and appearance you want. Nodes with the same group should appear in the same vertical plane, and nodes with the same rank will appear in the same horizontal plane.
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
}
}
")