问题
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.
回答1:
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.
回答2:
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).
来源:https://stackoverflow.com/questions/5968612/how-do-i-lengthen-edges-in-an-igraph-network-plot-layout-fruchterman-reingold