Reputation: 1076
How can I fix the location of node 0 to be on the most right, and 5 to be on the most left (5 is ok, what about 0)?
Here is my reproducibale code in R:
library(visNetwork)
nodes <- data.frame(id = 0:5,label=0:5)
edges <- data.frame( from=c(0,0,0,1,2,3,1,2,4),to=c(2,3,5,5,5,5,3,4,5))
visNetwork(nodes, edges)%>% visHierarchicalLayout(direction = "LR") %>% visEdges(arrows = "to")
Mor explanation: I need to form a readable graph that one node in my dataset be always on the left (i.e. finish node, shown as 5 here) and one be on the right (i.e. start node, shown as 0). I know to may be possible to use randomseed and try it for lots of combinations, but I am looking for a better solution that fixes the two nodes' positions by their ids to the most extreme left and right.
Upvotes: 1
Views: 887
Reputation: 684
I am not familiar with the package that much. But try this:
library(visNetwork)
nodes <- data.frame(id = 0:5,label=0:5)
edges <- data.frame( from=c(0,0,0,1,2,3,1,2,4),to=c(2,3,5,5,5,5,3,4,5))
visNetwork::visIgraphLayout(visNetwork(nodes, edges) %>% visEdges(arrows = "to") %>%
visEvents(selectNode = "function(properties) {
alert('selected nodes ' + this.body.data.nodes.get(properties.nodes[0]).id);}"))
You can then manually drag and place the nodes as you like, and wherever you like. Let me know if this workaround is good for you. This is the end result of me placing the way you asked in your question:
EDIT: Sorry I forgot about the direction of the edges. I've added them.
Upvotes: 3