我正在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解释。它的返回值是一个htmlwidget对象。
render_graph获取使用create_graph函数创建的dgr_graph对象。
你可以在DiagrammeR文档中看到
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代码:从下面提到的文档:"如果你想返回GraphvizDOT代码(也许是为了共享它或直接与Graphvi兹命令行实用程序使用它(,只需在render_graph((中使用output="DOT"即可。">
所以
- 您可以使用creategraph生成graphviz点代码
- 您可以在DiagrammeR中将graphviz点代码直接与grViz一起使用
这里的问题是,只使用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(在R.中不起作用
只有myGraph
可以正常工作。