0

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.

smpa01
  • 4,149
  • 2
  • 12
  • 23

2 Answers2

0

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
}
}
")
Raoul Duke
  • 435
  • 3
  • 13
  • I dn't know how to thank you. I picked my brain all morning to come to a solution. this is my first post in stack overflow. – smpa01 Apr 10 '19 at 18:30
  • Glad to help. I will warn you that this approach does not scale very well (gets messy with many blank nodes, ranks, and groups). – Raoul Duke Apr 10 '19 at 19:04
0

I also edited the original code to generate the following to approach a rotational scenario. 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
}
}
")
smpa01
  • 4,149
  • 2
  • 12
  • 23