在 R 中实现流程图

以下请忽视,流程图最好工具是 plantuml,支持对象图、组件图、状态图、用例图等

一般来说,流程图大家比较习惯用 MS 的visio 来实现,或退而求其次使用 MS word 或 Excel 也可以实现相同功能。其实流程图是一种很简单的图形模式,R 的diagram 包也提供了 Flow Chart 功能,只不过使用命令行来实现:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
library(diagram)
pos <- coordinates(pos = c(3, 3, 3, 3, 3, 3))
cc <- c("Start", LETTERS[2:16], "End")
openplotmat(main = "Flow Chart")
for (i in seq(1, 15, by = 3))
straightarrow(from = pos[i, ] , to = pos[i + 3, ])
for (i in c(2, 5, 8))
straightarrow(from = pos[i, ] , to = pos[i + 6, ])
segmentarrow(
from = pos[16, ],
to = pos[2, ],
path = "RVL",
dd = 0.15
)
bentarrow(from = pos[8, ], to = pos[6, ], path = 'H')
bentarrow(from = pos[6, ], to = pos[2, ], path = 'V')
straightarrow(from = pos[14, ], to = pos[17, ])
for (i in c(2, 7, 13, 14, 16))
textrect(pos[i, ],
radx = 0.08,
rady = 0.04,
lab = cc[i])
for (i in c(1, 17))
textround(pos[i, ],
radx = 0.08,
rady = 0.04,
lab = cc[i])
textdiamond(
mid = pos[8, ],
radx = 0.15,
rady = 0.08,
lab = c("Has", "Detect?")
)
textmulti(
mid = pos[4, ],
radx = 0.1,
rady = 0.05,
nr = 6
)
textmulti(
mid = pos[6, ],
radx = 0.1,
rady = 0.05,
nr = 5
)
textellipse(mid = pos[10, ], radx = 0.1, rady = 0.05)
text(pos[8, 1] + 0.2, pos[8, 2] + 0.03, "YES", cex = 0.8)
text(pos[11, 1] + 0.04, pos[11, 2], "NO", cex = 0.8)

以上代码呈现的结果是这样的: