22

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.

Monica
  • 231
  • 1
  • 2
  • 3

2 Answers2

16

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.

Sacha Epskamp
  • 42,423
  • 17
  • 105
  • 128
7

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

Vincent Traag
  • 506
  • 2
  • 5
  • 2
    scaling by a constant has no effect, unless you give `rescale=FALSE` parameter to the `igraph::plot` function – deeenes Dec 23 '14 at 14:18