3

I am currently analysing a multiplex network based on a dataset created by myself.

I want to be able to plot the network in a way that I can assign different colours to the two types of edges in by multiplex network.

The edgelist of this network looks like this edgelist

  • the multiplex network is called multi_g
  • it is an igraph object
  • the two types of ties are trade_tie and bilateralaid_tie
  • they edges are in different columns of the edgelist and hence in separated edge attributes

I tried to plot it with the following code:

plot(multi_g, 
     edge.color=c("brown", "green")[E(multi_g)$trade_tie+E(multi_g)$bilateralaid_tie],
     edge.arrow.size = 0.5,
     vertex.color="gray40", 
     vertex.label.color = "black",
     layout= layout_with_fr)

By using this formula many edges are not plotted.

Thank you in advance for your help.

If there is a way to plot it with ggraph I would also really appreciate it!

AnCo
  • 41
  • 4
  • Can you explain what you are trying to do? You show a piece of code that you say does not do what you want, but you did not explain what you want to happen. In the `edge.color` line you seem to be trying to index into a vector using a non-integer number, which makes no sense. – Szabolcs Dec 12 '21 at 19:28
  • [See here](https://stackoverflow.com/q/5963269/5325862) on making a reproducible example that is easier for folks to help with, such as a workable sample of data. Right now we can't see your output, so it's unclear what you're trying to fix exactly – camille Dec 13 '21 at 15:29
  • I voted to reopen as I can understand OPs question perfectly fine. OP has effectively two networks, with matching node identities. OP would like to visualise both networks in one plot, such that identical nodes are in the same position. OP would like to colour trade connections brown and aid connections green. When OP plots the graph some edges are not visible, as the edge layout engine probably is plotting them on top of each other. However, OP would like all edges to be visible. – Paul Brodersen Dec 14 '21 at 12:11
  • 1
    [Here](https://stackoverflow.com/questions/54373669/r-igraph-with-multiple-edges) is a possible solution, using curvature to offset the edge paths from one another. However, this does come with some limitations, as noted [here](https://stackoverflow.com/q/41964175/2912349) by @Tamas, one of the maintainers of igraph. – Paul Brodersen Dec 14 '21 at 12:17

1 Answers1

1

Thanks Paul! I was able to plot it like this using both the curving as you suggested and the ifelse () function to tell R when to colour which edge.

plot(multi_g, 
     edge.color=ifelse(E(multi_g)$trade_tie>0,"burlywood4","darkgreen"),
     edge.arrow.size = 0.1,
     edge.curved=0.3,
     vertex.color=c('green','brown')[(V(trade_g)$`Export/Import`=="export")+1], 
     vertex.label.color = "black",
     layout= layout_with_kk)
AnCo
  • 41
  • 4