如何在 DiagrammeR for R 中使用 GraphViz 图
How to use GraphViz graphs in DiagrammeR for R
我正在尝试在 DiagrammeR 中使用 GraphViz 图。我该怎么做?
myGraph = 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
}
")
然后我想在DiagrammeR中使用它,但它不允许。
render_graph(myGraph)
给出:
Error: class(graph) == "dgr_graph" are not all TRUE
有什么方法可以将 GraphViz 图转换或输入到 DiagrammeR 环境中吗?
grViz 采用描述图形的字符串(vis.js 样式):它由 vis.js 解释。它的 return 值是一个 htmlwidget 对象。
render_graph 接受一个 dgr_graph 对象,使用 create_graph 函数创建。
library(DiagrammeR)
# Create a simple NDF
nodes <-
create_nodes(
nodes = 1:4,
type = "number")
# Create a simple EDF
edges <-
create_edges(
from = c(1, 1, 3, 1),
to = c(2, 3, 4, 4),
rel = "related")
# Create the graph object,
# incorporating the NDF and
# the EDF, and, providing
# some global attributes
graph <-
create_graph(
nodes_df = nodes,
edges_df = edges,
graph_attrs = "layout = neato",
node_attrs = "fontname = Helvetica",
edge_attrs = "color = gray20")
# View the graph
render_graph(graph)
DiagrammeR 可以生成 Graphviz 代码:来自下面提到的文档:"If you'd like to return the Graphviz DOT code (to, perhaps, share it or use it directly with the Graphviz command-line utility), just use output = "DOT" in the render_graph()"
所以
- 您可以使用 create_graph 生成 graphviz 点代码
- 您可以在 DiagrammeR 中直接使用 grViz 的 graphviz 点代码
这里的问题是 render_graph(myGraph)
,仅使用 myGraph
就很有魅力。
library(DiagrammeR)
myGraph = 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
}
")
myGraph
render_graph(myGraph) Does not work in R.
只需 myGraph
即可。
我正在尝试在 DiagrammeR 中使用 GraphViz 图。我该怎么做?
myGraph = 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
}
")
然后我想在DiagrammeR中使用它,但它不允许。
render_graph(myGraph)
给出:
Error: class(graph) == "dgr_graph" are not all TRUE
有什么方法可以将 GraphViz 图转换或输入到 DiagrammeR 环境中吗?
grViz 采用描述图形的字符串(vis.js 样式):它由 vis.js 解释。它的 return 值是一个 htmlwidget 对象。
render_graph 接受一个 dgr_graph 对象,使用 create_graph 函数创建。
library(DiagrammeR)
# Create a simple NDF
nodes <-
create_nodes(
nodes = 1:4,
type = "number")
# Create a simple EDF
edges <-
create_edges(
from = c(1, 1, 3, 1),
to = c(2, 3, 4, 4),
rel = "related")
# Create the graph object,
# incorporating the NDF and
# the EDF, and, providing
# some global attributes
graph <-
create_graph(
nodes_df = nodes,
edges_df = edges,
graph_attrs = "layout = neato",
node_attrs = "fontname = Helvetica",
edge_attrs = "color = gray20")
# View the graph
render_graph(graph)
DiagrammeR 可以生成 Graphviz 代码:来自下面提到的文档:"If you'd like to return the Graphviz DOT code (to, perhaps, share it or use it directly with the Graphviz command-line utility), just use output = "DOT" in the render_graph()"
所以
- 您可以使用 create_graph 生成 graphviz 点代码
- 您可以在 DiagrammeR 中直接使用 grViz 的 graphviz 点代码
这里的问题是 ,仅使用 render_graph(myGraph)
myGraph
就很有魅力。
library(DiagrammeR)
myGraph = 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
}
")
myGraph
render_graph(myGraph)Does not work in R.
只需 myGraph
即可。