當我繪製與製圖網絡圖,像下面的例子玩具...如何使用圖解器最小化邊緣交叉點的數量,R?
library(DiagrammeR)
Dia <- function(edg, nodesd) {
nodes <- create_node_df( n=length(nodesd), label=nodesd,
width=0.3)
edges <- create_edge_df(from = edg$EveFrom, to = edg$EveTo,
rel = "leading_to")
graph <- create_graph( nodes_df = nodes, edges_df = edges)
render_graph(graph)
}
niv <- c("A","B","C","D","E","X","Y")
temp <- data.table(EveFrom=factor(c("A","A","A","A","B","C","D","E",
"X", "B"), levels=niv),
EveTo=factor(c("B","C","D","E","X","X","Y","Y","Y", "C"), levels=niv))
Dia(temp,niv)
我怎麼能告訴製圖到自動最小化邊交叉的次數?
在這個簡單的例子,如果C和B的位置被交換的結果不會有任何邊緣交叉。 在更復雜的示例中,我們無法刪除所有交叉點,但至少將其最小化。
隨着visnetwork我可以重新定位節點
但它有其他缺點,例如,它不會讓你將其導出爲矢量圖形。
是否也可以模仿我的visnetwork結果呢? (例如,在每個邊上添加標籤或更改邊緣寬度) – skan
10標籤:是,在'create_edge_df'(字符串向量)中添加'label'參數。 – bergant
寬度:使用'penwidth' = 3例如 – bergant