根据给定的双模igraph图中第一节点集的坐标来调整第二节点集的位置

时间:2019-05-14 10:36:39

标签: r igraph bipartite

对于基于igraph的双模式图,我想根据第一节点集的给定坐标来调整第二节点集的位置。有没有方便的方法?

这是一个可复制的示例,显示了我想做的事情。

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])

该图表明,第二个节点集的位置并未针对第一个节点集的可读性进行优化。这会干扰图形的可读性。 如何根据给定的第一节点集layout_given中的位置来优化第二节点集的位置?

enter image description here

必须有一种方法,但是我的编码知识太有限,无法理解layout.fruchterman.reingold()的编码方式,以了解如何在第一节点集的给定坐标上有条件地应用它。

0 个答案:

没有答案