[英]two column bipartite layout with igraph
I'm trying to plot a bipartite graph, but with two columns; 我试图绘制一个二部图,但是有两列; the function manual states that layout_as_bipartite()
"Minimize[s] edge-crossings in a simple two-row (or column) layout for bipartite graphs." 该功能手册指出, layout_as_bipartite()
“在二部图的简单两行(或列)布局中最小化边缘交叉”。 Trying with the example, I can only get two row graphs: 尝试该示例,我只能得到两个行图:
library(igraph)
library(dplyr)
# Random bipartite graph
inc <- matrix(sample(0:1, 50, replace = TRUE, prob=c(2,1)), 10, 5)
g <- graph_from_incidence_matrix(inc)
plot(g, layout = layout_as_bipartite,
vertex.color=c("green","cyan")[V(g)$type+1])
# Two columns
g %>%
add_layout_(as_bipartite()) %>%
plot()
It appears that layout_as_bipartite
only does rows, not columns, but it is easy to just modify the resulting layout. 看来layout_as_bipartite
仅处理行,而不处理列,但是仅修改结果布局很容易。 The layout is simply XY coordinates for the nodes, so to change from rows to columns, just switch X and Y. 布局只是节点的XY坐标,因此要从行更改为列,只需切换X和Y。
LO = layout_as_bipartite(g)
LO = LO[,c(2,1)]
plot(g, layout = LO, vertex.color=c("green","cyan")[V(g)$type+1])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.