1

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?

Data Science
  • 79
  • 2
  • 12
  • I'm not sure that I fully understand your question (I think an example would help). I tend to use tidygraph, which enables dplyr-style ordering of nodes, so that you could then create a directed graph as you mention above – p0bs Oct 05 '18 at 09:29
  • i use visNetwork or igraph, want edges to be in order of to, from and to;from – Data Science Oct 05 '18 at 12:31
  • 4
    Please include a [reproducible example](https://stackoverflow.com/a/5963610/1186342), including an example data structure in one of the graphing packages you mention, what you have tried so far, and an example of your desired output. – DanTan Oct 05 '18 at 12:33
  • If an edge is directed, it is both to and from. Do you mean at a specific node? – G5W Oct 05 '18 at 13:53

1 Answers1

1

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
struggles
  • 825
  • 5
  • 10