Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

igraph fixed node coordinates layout

Tags:

r

igraph

I have found this answer really useful. It helps me plot network/graphs and select the coordinates for the nodes in the plot.

However, the layout rescales the coordinates to -1 to 1. First off I tried to find out how it does this but couldn't. does it do something like this??

(coordinate - mean(coordinates))/(coordinate + mean(coordinates)

Second is there a way to keep the original coordinates? I woudl like to plat axes with the graph and so would prefer not to have top rescale everything.

like image 393
user1320502 Avatar asked Jun 28 '12 22:06

user1320502


1 Answers

The answer to your first question is in the source code of the plot.igraph function; type plot.igraph in the R prompt to get the full source code. There is a part in there which says:

layout <- layout.norm(layout, -1, 1, -1, 1)

layout.norm is another function of igraph which does the magic for you; type layout.norm to see how it works.

Now, the answer to the second question is really simple; just pass rescale=F to the arguments of plot, which makes igraph skip the entire branch in plot.igraph where layout.norm is called, so it will work with your original coordinates. You can then use xlim and ylim as usual to set the limits of the X and Y axes.

like image 135
Tamás Avatar answered Nov 14 '22 12:11

Tamás