How to colour edges in a multiplex network with R

Viewed 101

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!

1 Answers

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)
Related