前言
安装DiagrammeR 包:
install.packages("DiagrammeR")
例1:生态学物种研究流程图
library(DiagrammeR)
grViz("
digraph flowchart {
graph [layout = neato,
overlap = true,
outputorder = edgesfirst]
node [fontname = Helvetica, shape = rectangle] # node definitions with substituted label text
tab1 [label = '物种'pos='-1,1!']
tab2 [label = '位置'pos='-1,0!']
tab31 [label = '气候要素'pos = '3,0!']
tab32 [label = '气候要素'pos = '3,-1!']
tab4 [label = '气候-物种\n分布模型',pos = '1,0!',]
tab5 [label = '预测物种\n适宜分布区'pos = '1,-1!']
tab6 [label = '投影预测\n的分布区'pos = '1,-2!']
tab7 [label = '地图',pos = '-1,-2!']
anotation1 [pos='-2,1!',label='检索物种名\n或同义词',color=white]
anotation2 [pos='-2,0!',label='检索物种\n分布数据',color=white]
anotation3 [pos='4,0!',label='当前地表\n气候数据',color=white]
anotation4 [pos='4,-1!',label='潜在地表\n气候数据',color=white]
anotation5 [pos='-2,-2!',label='全球或\n区域地图',color=white]
# edge definitions with the node IDs
tab1 -> tab2;
tab2 -> tab4;
tab31 -> tab4;
tab32 -> tab5;
tab4 -> tab5 -> tab6;
tab7 -> tab6;
}
")
结果:
例2:QQ群进群验证流程图
library(DiagrammeR)
grViz("
digraph flowchart {
# node definitions with substituted label text
node [fontname = Helvetica, shape = rectangle]
tab1 [label = @@1,color=pink,fill=red]
tab2 [label = @@2]
tab3 [label = @@3]
tab5 [label = @@5]
tab7 [label = @@7]
tab6 [label = @@6]
tab9 [label = @@9]
node [fontname = Helvetica, shape = circle, penwidth=2.0]
tab4 [label = @@4]
tab8 [label = @@8]
# edge definitions with the node IDs
tab1 -> tab2 -> tab3;
tab3 -> tab4 -> tab5;
tab5 -> tab6[label ='是',fontname = Helvetica];
tab5 -> tab7[label ='否',fontname= Helvetica];
tab3 -> tab8 -> tab9;
}
[1]: '开始'
[2]: '改备注'
[3]: '性别'
[4]: '女'
[5]: '单身'
[6]: '爆照'
[7]: '分手'
[8]: '男'
[9]: '发红包'
")
结果: