r - 将不同的 grViz 组合成一个图
问题描述
我想将不同DiagrammeR
的图组合成一个图形。这些图的生成如下例所示:
library(DiagrammeR)
pDia <- grViz("
digraph boxes_and_circles {
# a 'graph' statement
graph [overlap = true, fontsize = 10]
# several 'node' statements
node [shape = box,
fontname = Helvetica]
A; B; C; D; E; F
node [shape = circle,
fixedsize = true,
width = 0.9] // sets as circles
1; 2; 3; 4; 5; 6; 7; 8
# several 'edge' statements
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
}
")
pDia
因此,我想将像pDia
, class "grViz" "htmlwidget"
, 这样的图组合成一个带有标签的图像A
,B
等等。我尝试使用该exportSVG
函数导出绘图的 svg 文件。因此,将有可能使用magick
包来导入和处理此类(即"grViz" "htmlwidget"
)的不同情节。DiagrammeR
但是,此功能在较新版本的软件包中不可用。有什么想法可以将这些图组合在一个可以导出到图形文件的图形中,例如pdf
or tiff
?
解决方案
也许以下方法之一将满足您的需求。
- 您可以通过将它们添加到同一个
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;
}")
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")
然后,您可以通过在组合脚本中排列节点的方式排列多个图表。
推荐阅读
- angularjs - ng-bind-html 和 unsafe 不起作用
- firebase - 取决于 Firebase 上的数据 - 构建按钮,包括图像和数据
- javafx - 有没有办法在 JavaFX for ARM 中禁用虚拟键盘?
- python - Google App Engine 部署问题 - 未找到主应用
- logstash - 如何使用 logstash 过滤器删除事件
- android - Android Work Manager One time Request 从工作人员返回空白结果
- javascript - 如何向 NodeJs 中的选择性 API 添加“授权”检查?
- android - 有没有办法在 Android Oreo 地理围栏触发器中进行异步操作?
- xcode-server - 使 Xcode 服务器在具有动态 IP 的本地网络之外可用
- java - 如何将一个 int 值与多个字符串值进行比较。所以它适用于数据库。转换值失败