Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fixing multiple node coordinates when carring out clustering algorithm in igraph

Tags:

r

igraph

Was wondering if the following is possible:

Currently, I have a subset of nodes in a graph, (graph A), which belongs in another separate and larger graph (graph B).

I would like to preserve the layout from graph B pertaining to this subset of nodes when running a layout generation algorithm on graph A. Could be any of the layout algorithms.

 layout.circle(graph, params)
 layout.sphere(graph, params)
 layout.fruchterman.reingold(graph, ..., dim=2, params)
 layout.kamada.kawai(graph, ..., dim=2, params)
 layout.spring(graph, ..., params)
 layout.reingold.tilford(graph, ..., params)
 layout.fruchterman.reingold.grid(graph, ..., params)
 layout.lgl(graph, ..., params)
 layout.graphopt(graph, ..., params=list())
 layout.mds(graph, dist=NULL, dim=2, options=igraph.arpack.default)
 layout.svd(graph, d=shortest.paths(graph), ...)
like image 771
Buthetleon Avatar asked Aug 28 '26 10:08

Buthetleon


1 Answers

You can use the minx, maxx, miny and maxy arguments of layout.fruchterman.reingold() or layout.kamada.kawai() to fix some vertices completely. These arguments specify vertex-specific lower and/or upper limits for the coordinates.

For the vertices you want to fix, set them exactly to the value to fix, and for the other vertices set minx to some small negative values (-Inf might work, too), and set maxx to some large value, (again, maybe Inf works, too).

You might need to use the rescale=FALSE argument in plot.igraph() to avoid rescaling the complete layout, for both the first and second graph.

Edit:

From the manual:

'minx' If not 'NULL', then it must be a numeric vector that gives lower boundaries for the 'x' coordinates of the vertices. The length of the vector must match the number of vertices in the graph.

'maxx' Similar to 'minx', but gives the upper boundaries.

For example:

g <- graph.star(10, center=1)

minx <- rep(-Inf, vcount(g))
maxx <- rep( Inf, vcount(g))
minx[1] <- 0
maxx[1] <- 0
lay <- layout.fruchterman.reingold(g, minx=minx, maxx=maxx, miny=minx, maxy=maxx)

plot(g, layout=lay)

fixes the first vertex into (0,0) (might be modified by rescaling, to avoid rescaling, use rescale=FALSE in plot() and set the plotting limits).

enter image description here

like image 120
Gabor Csardi Avatar answered Aug 31 '26 00:08

Gabor Csardi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!