CSV(邻接矩阵)表示图形,我如何在R中使用igraph绘制图形+边长?

时间:2013-11-06 23:08:36

标签: igraph

我有像这样的CSV格式(表示图形的邻接矩阵):

0,0,3.16023,7.98319,4.97476,0,0,7.5256,0,3.61683
0,0,0,0,6.66346,3.78653,0,0,0,5.28698
3.16023,0,0,9.30634,0,0,0,0,6.97926,6.94043
7.98319,0,9.30634,0,7.83085,0,0,6.32612,3.90679,0
4.97476,6.66346,0,7.83085,0,1.72829,4.3236,0,9.29742,0
0,3.78653,0,0,1.72829,0,5.51931,0,0,1.70871
0,0,0,0,4.3236,5.51931,0,0,9.81537,0
7.5256,0,0,6.32612,0,0,0,0,4.16524,0
0,0,6.97926,3.90679,9.29742,0,9.81537,4.16524,0,5.78895
3.61683,5.28698,6.94043,0,0,1.70871,0,0,5.78895,0

我使用R和igraph库来绘制它。

library(igraph)
mygraph=read.csv("graph.csv", header=FALSE)
M <- as.matrix(mygraph)
g <- graph.adjacency(adjmatrix=M, mode="undirected", weighted=TRUE, diag=FALSE)
plot(g)

如何打印边长/重量?绘制图形(http://i.stack.imgur.com/X6pkw.png)而没有边长。如何在图中打印边缘长度?

1 个答案:

答案 0 :(得分:2)

plot(g, edge.label=round(E(g)$weight, 3))

请参阅手册中的?igraph.plotting