Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I lengthen edges in an igraph network plot (layout=fruchterman.reingold)?

Tags:

Trying to do a network plot in R. How do I lengthen edges in a network graph using IGraph?

I actually want to use the fruchterman-reingold layout. Is there some way I can make that force-based algorithm "springier" so that my vertices are further apart?

thanks.

like image 630
Monica Avatar asked May 11 '11 18:05

Monica


2 Answers

You can control the Fruchterman-Reingold algorithm using the layout.fruchterman.reingold function. see: help('layout.fruchterman.reingold'). A setup that I often use and gets you a little more spacing is:

l <- layout.fruchterman.reingold(g,niter=500,area=vcount(g)^2.3,repulserad=vcount(g)^2.8) plot(g,layout=l) 

where g is your graph object. Best to just test different values of these parameters for your graph and see what works. Especially repulserad influences the spacing in a graph. The default is the square of the number of nodes, so higher values should get you more spaced graphs.

like image 156
Sacha Epskamp Avatar answered Oct 24 '22 04:10

Sacha Epskamp


If the layout.fruchterman.reingold algorithm still does not give what you want by tweaking the parameters, simply do the following. Every layout returns a set of coordinates, with the x- and y-coordinate in the first and second column respectively. You can apply any transformation you like here, and if you would just like to scale it, simply use

L = layout.fruchterman.reingold(G)*s; #Scaling factor s 

More fancy transformations are of course also possible. Just for the record, you can also edit the layout manually with your mouse by using tkplot(G, layout=L). You can get the coordinates back via L = tkplot.getcoords(1).

like image 33
Vincent Traag Avatar answered Oct 24 '22 04:10

Vincent Traag