1

I would like to adjust the position of a second nodeset based on the given coordinates of a first nodeset for a two-mode plot with igraph. Is there a convenient way of doing so?

Here is a replicable example that shows what I would like to do.

library(igraph)

set.seed(01)

# get sample matrix
bip <- matrix(sample(0:1,10*20, replace=TRUE),10,20)

# transform to bipartite incidence matrix for plotting
g <- graph_from_incidence_matrix(bip)

# initialise empty matrix for coords of the first nodeset
layout_given <- matrix(0, 10, 2)
# sample some coordinates that represent those which are given 
layout_given[,1] <- sample(-2.435651:3.670977,10, replace = T)
layout_given[,2] <- sample(-2.435651:3.670977,10, replace = T)

# these are the standard positions of the nodes the algorithm 
# layout.fruchterman.reingold assigns
layout_fr = layout.fruchterman.reingold(g)

# replace the given positions with those generated by the algorithm. 
# these are the first 10 in the layout 30x2 layout matrix 
# (because there are 10 nodes of the first nodeset) with those that I would like 
# to hold fixed
layout_fr[1:10,] <- layout_given


plot(g, 
 layout = layout_fr,
 vertex.shape= c("circle", "square")[V(g)$type+1],
 vertex.color= c("red", "orange")[V(g)$type+1])

The plot shows that positioning of the second nodeset is not optimised for readability with regards to the first nodeset. This interferes with the readability of the graph. How can I optimise the position of the second nodeset based on the given positioning in the first nodeset layout_given?

enter image description here

There must be a way to do that but my coding knowledge is too limited to understand the way layout.fruchterman.reingold() is coded to understand how to apply it conditional on the given coordinates for the first nodeset.

9
  • 1
    Why not use a bipartite layout? Commented May 14, 2019 at 12:47
  • Good idea but if it was possible to solve this puzzle it would absolutely great, especially for plotting two-mode networks with one geo-referenced node set
    – S Front
    Commented May 14, 2019 at 12:50
  • 1
    The link in my first comment leads you to the documentation for computing a bipartite layout in igraph for R. I suggest you start there. Commented May 14, 2019 at 12:52
  • I don't think layout_as_bipartite() actually helps because the real network that I have consists of about 30 nodes of the first node type and more than 200 of the second nodeset, so it is difficult to see which nodes of the first node type are connected with the second node type. Any further suggestions? In addition, I have second network one-mode network that I plot underneath, so I guess it would be better to use fruchtermann.reingold ?
    – S Front
    Commented May 14, 2019 at 12:58
  • 1
    However, pretty much no matter which layout, any random or approximately random graph with >50-100 nodes will always look like a hairball. The bipartite layout algorithm tries to minimize edge crossings, which maximizes your chance to be able to see differences in the connectivity between different nodes. But there is only so much you can do in untangling 30 * 200+ relationships in 2 dimensions. Commented May 14, 2019 at 16:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.