Change the order of Edges in Network Graph

267 Views Asked by At

is there anyway to change the order of the edges in a network graph,

using any of the igraph, visNetwork or even JS within R?

For example i would like a network to have all the arrows going to, from and to;from all in order,

however found nothing online to edit the way the order of the edges is produced,

any help appreciated?

1

There are 1 best solutions below

0
On

Using igraph you could convert the graph into a data frame and then arrange it:

set.seed(4321)
g <- igraph::sample_gnp(10, .4) %>%
  igraph::as.directed()
df <- igraph::as_data_frame(g)
dplyr::arrange(df, from)

This hsould give you something like:

   from to
1     1  4
2     1  5
3     1  6
4     1  7
5     1  8
6     1 10
7     2  4
8     2  8
9     2  9
10    2 10