When I plot a network graph with diagrammer, like the following toy example...
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)
How can I tell diagrammer to minimize the number of edge crossings automatically?
In this simple example if C and B positions were exchanged the result wouldn't have any edge crossing. In more complex examples we cannot remove all crossings but at least minimize it.
With visnetwork I can relocate the nodes
But it has other drawbacks, for example it doesn't let you export it as a vector graphic.
PD: This is the output with bergant solution (with labels hidden):
use dot
layout option (made with inspiration from here )
# install.packages(c("DiagrammeR"), dependencies = TRUE)
library(DiagrammeR)
grViz("
digraph dot {
graph [layout = dot] # dot, neato, twopi, and circo
A -> {B C D E}
B -> {C X}
C -> {X}
D -> {Y}
E -> {Y}
X -> {Y}
}")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.