Indicate the position of some nodes in the graph

Is there a way to indicate the position of a certain subset of nodes in a connected graph, while some algorithm determines the position of other nodes? I hope to find an algorithm that treats the edges as a spring so that they are not too far from other nodes, such as graphopt . I examined several other algorithms in igraph, for example, lgl, drl, but none of them seem to allow you to specify the position of nodes, I should allow the algorithm to have full control over the location of all nodes.

I ask about this because I have a data network, and on some nodes I can find approximate geographical coordinates. I hope to show the entire network on a map. By looking at the network on a map, I can iteratively identify more nodes with some geographical identity, and in the end I get a geo-referenced graph with decent accuracy, at least visually.

I started with igraph to R, but I am open to try other packages / language or even a GIS tool if there is something close to what I am looking for.

Thanks!

[EDIT]

In the end, this question is not a very good question, but since I started it, let me describe in more detail what I'm looking for. I hope that what I'm looking for makes sense, and someone has already done this before.

The G5W proposal is moving where I want, but I hope to apply the principle of the original algorithm after it is fixed in the right direction.

The FR method says that:

We have only two principles for plotting:

  • The vertices connected by an edge should be drawn next to each other.
  • The vertices should not be drawn too close together.

Therefore, I thought that a large cycle, including the path 10-8-4-1-3, should shrink and get closer to the other nodes. I thought I could find the layout as shown below if I fix the four points, as the G5M did.

What i want

I thought that the algorithm could accidentally create such a graph, and tried, as shown below, a very crude brute force method. But the algorithm never generated what I was looking for ... I think I need to point out some kind of exception to the algorithm to handle these edges between the attached nodes.

library(igraph) set.seed(1) g = erdos.renyi.game(10, 0.3) LO = layout_with_fr(g) plot(g, layout=LO) n <- nrow(LO) i <- 0 for (i in 1:100000) { # i <- i + 1 LO <- layout_with_fr(g) chk <- c(all(LO[c(5,7),2] >= sort(LO[-c(5,7),2])[n-3]), # 5,7 should come close to top all(LO[c(2,9),2] <= sort(LO[-c(2,9),2])[2]), # 2,9 near bottom all(LO[c(2,7),1] <= sort(LO[-c(2,7),1])[2]), # 2,7 toward left all(LO[c(5,9),1] >= sort(LO[-c(5,9),1])[n-3]) # 5,9 toward right ) if (all(chk)>1 ) break } 

[EDIT2]

Still looking for a way to do this. I found the Stick Force Layout page on d3, which seems to be what I want. The problem is that I'm not sure that I can export the coordinates when I'm happy with the layout. Also, I probably want to be able to keep the intermediates. So this means that I should be able to bind the coordinates along with the attributes if they are stuck or not. And this data is in and out. If this is trivial for people who know JS, please give me a pointer. I am trying to come up with a JSON In / Out interface if not.

A graph without specifying the location of a user-defined node defined by a power distribution algorithm

graph, no node pos specified

I choose the position of some node to make the graph tree-like. This is just one example, but I want to say that I want to be able to get a rough layout without having to determine the position of each individual node.

what I'd come up with, for example, tree-like layout

+5
source share
1 answer

You do not provide any sample data for the graph or the specific layout you are trying to achieve, so I will take a random graph and a simple configuration as the goal. The idea is that you can let any algorithm lay out all the points, and then adjust the position of the ones you want to indicate.

 ## basic graph for illustration library(igraph) set.seed(1) g = erdos.renyi.game(10, 0.3) LO = layout_with_fr(g) plot(g, layout=LO) 

Starting position

OK, now suppose we want to take the nodes 2,5,7 and 9 and put them in a box without crossing the edges. I want to make a basic box layout and move it so that these four nodes and their edges are removed from the rest of the graph. I just move these four nodes so that they are slightly higher than the rest.

 UB = max(LO[,2]) DesiredLO = matrix(c(0,0,0,1,1,0,1,1), nrow=4, ncol=2, byrow=TRUE) LO[c(2,7,9,5), ] = DesiredLO + matrix(rep(LO[2,], 4), ncol=2, byrow=TRUE) LO[c(2,7,9,5), 2] = LO[c(2,7,9,5), 2] + UB - LO[2,2] + 1 plot(g, layout=LO) 

Selected sites hosted specifically

Perhaps you can adapt this to whatever you want. If not, use this example or something like that to clarify what you want.

+5
source

Source: https://habr.com/ru/post/1274682/


All Articles