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开发者_Python百科 there some way I can make that force-based algorithm "springier" so that my vertices are further apart?
thanks.
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.
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)
.
精彩评论