我正在使用 DiagrammeR 包来创建这样的流程图:
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
}
}
")
这将创建一个像这样的图表:
但是,我不想手动填写框中的值,而是想从列名对应于每个框的数据框中填写值:
d <- read.table(text = "P1 P2 P3 A1 P4 P5 A2 AP A3
23 46 38 101 378 344 33 222 45", header = T)
我只能做到这一点:
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))
但是,它创建了以下流程图,甚至与我最初创建的流程图都不相近:
有人可以建议我如何设置每个盒子的排名和顺序吗?
谢谢!