输入矩阵是连接权重时,如何利用R中的igraph包生成图
————————————————————————————————————————————
library(igraph)#加载包
mygraph=read.csv("d:/desktop/n.csv", header=TRUE,sep = ",",row.names=1)#读取数据
我的数据长这样

m<- as.matrix(mygraph)#输入数据转换为matrix
g <- graph.adjacency(adjmatrix=m, mode="directed", weighted=TRUE, diag=FALSE)#生成有向图,权重设置TRUE
plot(g, edge.label=round(E(g)$weight, 3))#$带权重标注的网络图,可以通过——?igraph.plotting 查看igraph绘图相关参数
输出的图如下:

E(g)$weight#查看连边权重
结果如下:
[1] 0.83 0.76 0.78 0.40 0.67 0.73 0.79 0.71 0.75 0.65 0.69 0.48 0.72 0.82 0.88 0.58 0.70
[18] 0.73 0.60 0.54 0.65 0.56 0.68 0.54 0.61 0.59 0.47 0.67 0.64 0.64 0.47 0.51 0.60 0.50
[35] 0.47 0.61 0.44 0.56 0.66 0.72 0.71 0.72 0.65 0.63 0.51 0.69 0.66 0.59 0.68 0.73 0.62
[52] 0.71 0.51 0.76 0.77 0.51 0.88 0.92 0.70 0.77 0.44 0.80 0.87 0.77 0.66 0.51 0.52 0.77
[69] 0.64 0.68 0.47 0.52
——————————————————————————————
网友评论