我使用igraph绘制非定向力网络。igraph中的顶点标签
我有nodes
一个数据帧和links
如下:
> links
source target value sourceID targetID
1 3 4 0.6245 1450552 1519842
2 6 8 0.5723 2607133 3051992
3 9 7 0.7150 3101536 3025831
4 0 1 0.7695 401517 425784
5 2 5 0.5535 1045501 2258363
> nodes
name group size
1 401517 1 8
2 425784 1 8
3 1045501 1 8
4 1450552 1 8
5 1519842 1 8
6 2258363 1 8
7 2607133 1 8
8 3025831 1 8
9 3051992 1 8
10 3101536 1 8
我绘制这些使用igraph
如下:
gg <- graph.data.frame(links,directed=FALSE)
plot(gg, vertex.color = 'lightblue', edge.label=links$value, vertex.size=1, edge.color="darkgreen",
vertex.label.font=1, edge.label.font =1, edge.label.cex = 1,
vertex.label.cex = 2)
在这个情节,IGRAPH采用了代理索引source
和target
作为顶点标签。
我想使用真实的ID,在我的links
表中表示为sourceID
和targetID
。
所以,对于:
source target value sourceID targetID
1 3 4 0.6245 1450552 1519842
这将显示为:
(1450552) ----- 0.6245 ----- (1519842)
相反的:
(3) ----- 0.6245 ----- (4)
(注意,代理索引是从零开始的links
数据帧索引,并在nodes
数据框中索引一个,这个偏移量是1 ary为igraph
绘图)。
我知道我需要以某种方式match
或map
代理索引他们的nodes
数据帧中的相应name
。然而,由于我不知道igraph绘制标签的顺序,所以我很茫然。
我该如何做到这一点?
我已经咨询以下问题无济于事:
Vertex Labels in igraph with R how to specify the labels of vertices in R R igraph rename vertices
谢谢您的回答。真的很有用。当你说'你可以传递...到顶点参数'时,你究竟是什么意思?你的意思是设置'vertex.attr = merge ....'? – Chuck
我的意思是'graph.data.frame(...,vertices = merge(...))'。 – lukeA
非常好,非常感谢。 – Chuck