I am using the DiagrammeR package to create a flowchart like this:
grViz("
digraph boxes_and_circles {
# left 'node' statements
node [shape = box,
fontname = Helvetica,
width = 2,
penwidth = 2,
color = lightblue]
A1; P1; P2
# right node statements
node [shape = box,
fontname = Helvetica,
width = 2,
penwidth = 2,
color = steelblue]
A2; A3; P3; P4; P5; AP
# edge statements
P1->P2 P2->P3 P3->P4 P4->P5 P5->AP
A1->A2->A3
A2->P4
A3->AP
# define ranks
subgraph {
rank = same; A2; P4
}
subgraph {
rank = same; A1; P2
}
}
")
This creates a graph like this:
However, instead of manually filling in the values in the boxes, I want to fill in values from a dataframe where the column names correspond to each of the boxes:
d <- read.table(text = "P1 P2 P3 A1 P4 P5 A2 AP A3
23 46 38 101 378 344 33 222 45", header = T)
I have been able to go only so far with this:
node.df <- create_node_df(n = 9, shape = 'box', color = 'aqua',
type = c(rep('box',9)),
label = c('P1','P2','P3','P4','P5','AP','A1','A2','A3'),
tooltip = c('P1','P2','P3','P4','P5','AP','A1','A2','A3'),
penwidth = 2,
fontsize= 35,
face = 'bold',
width = 5)
edge.df <- create_edge_df(from = c(1,2,3,4,5,7,8),
to = c(2,3,4,5,6,8,9),
rel = 'leading_from')
render_graph(create_graph(nodes_df = node.df,
edges_df = edge.df))
However, it creates the following flowchart that is not even close to what I was initially creating:
Can someone suggest how do I set the ranking and order of each box?
Thanks!