0

Is there a way to weigh layout according to node attributes in igraph? In other words, how to get nodes that share the same characteristics (but do not have edges between them) cluster more closely together?

While many layout functions can take edge weight into account, the nodes that I want to be closer to each other do not have edges between them. An example of such situation is if the graph is bipartite. Using layouts such as fruchterman.reingold is not very informative as vertices of the two different types are interspersed. However, I do not want it be be as extreme as the layout.bipartite option either as it would be rather messy when there are lots of vertices. What I wish is to have a layout that is somewhere between these two, having vertices of the same type to be on one side, and also cluster according to certain attributes, with edges between the two types.

Any idea or suggestion will be greatly appreciated. Thanks!

iemnar
  • 13
  • 2
  • You could try this trick: create additional extra edges in the graph, between each pair of vertices that you want to attract each other. Then try finding an "optimal" edge weight for the new edges, relative to the original, real edges. – Gabor Csardi Jul 21 '15 at 15:00
  • Please see the comment below – iemnar Jul 21 '15 at 22:31

1 Answers1

0

igraph layouts are simply matrices with 2 columns and N rows, so you can easily re-use one layout with another graph as long as the two graphs share the same number of nodes. You can make use of this here: create a graph where you connect the nodes that you want to be placed close to each other, calculate the layout using this graph, and then plot your original graph with the layout you have calculated.

Tamás
  • 47,239
  • 12
  • 105
  • 124
  • Thank you both for your response, I have actually thought of these two solutions, just wasn't sure if there are more straightforward ways. I will give both methods a try and will post afterwards! – iemnar Jul 21 '15 at 22:30
  • I have tried out both methods, one better than the other in different circumstances. Another way is to make the layouts separately for each types of node, use merge_coord, and plot the bipartite graph using the merged layout. – iemnar Aug 12 '15 at 21:59