Question

It appears that I can't find the solution for the following issue:

I want to plot the edges by size (length, not width).

I mean if the edge between V1 and V2 vertices is a value equal to 20 I would like to plot that edge exactly 20 pixels.

If another edges between V2 and V3 is 60 that edge will be longer in the plot.

I can't find how to specify the edge size or length. Maybe it's not possible with a simple codeline like other attributes for plotting (vertex size, colors, width etc) Igraph tutorials didn't give answer to this. Probably it's difficult.

The shape-orientation of graph is not important even if the fixed edges will give a constant shape I guess.

The graph is undirected but has many vertex and edge sequences.

Was it helpful?

Solution

There is no edge attribute in igraph that would let you control the length of the edge directly. The primary reason is that satisfying all the length constraints exactly is impossible unless your graph has a very sparse structure and/or the lengths are very specific.

The only thing that comes to my mind is a technique called multidimensional scaling (MDS). Without going into the gory details, the input of the MDS is an n x n matrix (where n is the number of vertices in your graph) and the matrix cells contain the desired distances between the points. The output of MDS is an arrangement of the vertices in some lower-dimensional space (typically the 2D plane) where the total squared difference between the actual and the desired distances is minimized. In particular, if the desired distances can be satisfied exactly in the 2D space, MDS will find that configuration for you. igraph includes MDS as a layout algorithm in the layout_mds method of Graph objects.

Now, here comes the catch. I mentioned that the distance matrix is of size n x n. The problem is that this means that you have to prescribe a distance for every vertex pair, not only the connected ones. My impression is that this is not the case in your problem (i.e. you only have distances for the connected vertex pairs), in which case MDS is useless unless you can "approximate" the distances of disconnected vertex pairs somehow - but in this case the layout will also be just an approximation.

Another option is the Kamada-Kawai layout (see Kamada, T. & Kawai, S. (1989). An algorithm for drawing general undirected graphs. Information Processing Letters, 31, 7-15), where edges are modeled as springs, each spring having a prescribed equilibrium length. The layout will try to settle in a configuration that is close to the physical equilibrium (in which case all the spring length are close to their equilibrium length so they exert no force on their endpoints, i.e. the vertices). The problem here is that the Kamada-Kawai layout in igraph is not prepared to handle different equilibrium lengths for the springs, i.e. each link is assumed to have the same "desired" length. If you are willing to implement the Kamada-Kawai layout yourself from scratch in Python, then this could be another possibility.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top