我想得到类似的东西
我已经将Diagrammer和Visnetwork包用于其他图表,所以使用它们将是一个奖励。
library(DiagrammeR)
library(visNetwork)
from=c("A","A","A","A","B","B","B","C","C","D")
to=c("B","C","D","E","C","D","E","D","E","E")
nodesd=c("A","B","C","D","E")
使用Diagrammer:
nodes <- create_node_df( n=length(nodesd), label=nodesd, width=0.3)
edges <- create_edge_df(from = factor(from, levels=nodesd), to = factor(to, levels=nodesd), rel = "leading_to")
graph <- create_graph(nodes_df = nodes, edges_df = edges)
render_graph(graph)
我也尝试过使用set_node_position(),但似乎没有任何区别。
使用Visnetwork
nodes <- data.frame(id=nodesd, label= nodesd )
edges <- data.frame(from=from, to =to, length=150)
visNetwork(nodes,edges, width="100%" , height="100%") %>%
visNodes(shape = "circle") %>% visEdges(arrows = 'to', smooth =T)
我可以手动拖动它们但是如果你有很多图形,那么你不想做的事情,结果也不好。
我必须通过添加线
垂直地进行visnet %>% visHierarchicalLayout()
最后。但它不能很好地工作,因为许多边缘消失了。
如果我想获得横向对齐,我需要将其添加到节点定义中。
level = c(1,1,1,1,1)
答案 0 :(得分:2)