简体   繁体   English

将二部网络的 igraph 布局从垂直方向旋转到水平方向

[英]Rotate igraph layout for bipartite networks from vertical to horizontal orientation

I have created a bipartite network with vertical orientation with:我创建了一个垂直方向的二分网络:

edgelist <- read.table(text="Person    Event
                         Amy       football
                         Bob       picnic
                         Sam       artshow", 
                       header=TRUE)
igraph <- graph.data.frame(edgelist)

V(igraph)$type <- V(igraph)$name %in% edgelist[,1]
plot(igraph, vertex.label=V(igraph)$Name, vertex.size=7,vertex.label.dist=2, layout=layout_as_bipartite) 

I was wondering if I can create the same plot with horizontal orientation and the node names next to each node.我想知道是否可以创建具有水平方向和每个节点旁边的节点名称的相同图。

To get the original layout matrix, one can use the following code, after one have set the type of the graph:要获得原始布局矩阵,可以使用以下代码,在设置图形类型后:

LO <- layout_as_bipartite(igraph)

Now it has the correct coordinates for the bipartite plotting, but it plots the graph in two rows.现在它具有用于二部绘图的正确坐标,但它将图形绘制成两行。 To plot it in the desired orientation, one can flip the X and Y coordinates, by the backward indexing of the matrix.要以所需的方向绘制它,可以通过矩阵的向后索引来翻转 X 和 Y 坐标。

plot(igraph, vertex.label=V(igraph)$Name, vertex.size=7,vertex.label.dist=2, layout=LO[,2:1])

Edit编辑

I forgot that you want to reposition the labels.我忘了你想重新定位标签。 Fortunately, you have set the $type parameter as the indicator of the edges' tail nodes.幸运的是,您已将$type参数设置为边尾节点的指示符。 You can use the vertex.label.degree argument of the plot function.您可以使用 plot 函数的vertex.label.degree参数。 Multiplying the mentioned logical vector attribute with pi has solved that problem too.将提到的逻辑向量属性与pi相乘也解决了这个问题。 So the position of the tails' labels are rotated by pi , while on the right, you have the labels rotated by 0. I have also plotted the labels a bit further from the nodes.因此,尾部标签的位置由pi旋转,而在右侧,标签旋转了 0。我还绘制了离节点更远的标签。

plot(igraph, vertex.label=V(igraph)$Name,
 vertex.size=7, vertex.label.dist=3, layout=LO[,2:1],
 vertex.label.degree = pi*V(igraph)$type)

更新的二分水平图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM