[英]How to refer to multiple DiagrammeR GraphViz graphs in a shinydashboard
[英]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 解釋的。 它的返回值是一個 htmlwidget 對象。
render_graph 使用使用 create_graph 函數創建的 dgr_graph 對象。
你可以在DiagrammeR doc中看到
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 代碼:來自下面提到的文檔:“如果您想返回 Graphviz DOT 代碼(或許,共享它或直接與 Graphviz 命令行實用程序一起使用),只需使用 output = "DOT “在render_graph()”中
所以
這里的問題在於 ,只使用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
工作正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.