也许以下方法之一可以满足您的需求。
- 您可以通过将附加/断开连接的图表添加到相同的图表中来添加它们
digraph
称呼。例如,我们可以通过在另一个图之后添加节点和边来将另外两个图(U -> V -> W 和 X -> Y -> Z)添加到图的右侧;您只需确保节点的命名与前面图中的节点的命名不同即可。然而,这可能会导致大型复杂的脚本,并且可能不适合您的工作流程。
library(DiagrammeR)
pDia <- grViz("
digraph boxes_and_circles {
# your existing graph here
# 2nd graph
U -> V -> W;
# 3rd graph
X -> Y -> Z;
}")
- 鉴于您想要静态输出,直接进入可能会更容易graphviz http://www.graphviz.org/。组合图形的一种方法是将它们作为图像添加到现有节点。例如,如果您有两个保存为 png 的图表(其他格式) https://graphviz.org/doc/info/output.html:
cat(file="so-65040221.dot",
"
digraph boxes_and_circles {
graph [overlap = true, fontsize = 10]
node [shape = box, fontname = Helvetica]
A; B; C; D; E; F
node [shape = circle, fixedsize = true, width = 0.9]
1; 2; 3; 4; 5; 6; 7; 8
A->1 B->2 B->3 B->4 C->A
1->D E->A 2->4 1->5 1->F
E->6 4->6 5->7 6->7 3->8
}")
# This will write out two pngs. We will use these as examples for us to combine
system("dot -Tpng -Gdpi=300 so-65040221.dot -o so-65040221A.png -o so-65040221B.png")
然后创建一个新图表来读取 png 并将它们添加到节点
cat(file="so-65040221-combine.dot",
'graph {
node [shape=none]
a [label="", image="so-65040221A.png"];
b [label="", image="so-65040221B.png"];
}')
我们执行此操作并输出为 pdf
system("dot -Tpdf so-65040221-combine.dot > so-65040221-combine.pdf")
# or output tiff etc
# system("dot -Ttif so-65040221-combine.dot > so-65040221-combine.tiff")
然后,您可以通过在组合脚本中排列节点的方式来排列多个图形。