语法笔记
- 使用R语言iGraph包绘制无向点线图
con <- matrix(scan(“dividedmap6”, what=character(), n=1000), , 2, byrow = TRUE)//读入文件前1000行,生成两列的矩阵
library(igraph)
g <- graph.edgelist(con, directed=F)//无向图
plot(g, layout=layout.kamada.kawai, vertex.label = NA, vertex.size=5)//绘制,结点大小为5
- 产生随机序列
runif(100,0,100)//存在小数
sample(seq(0,100,by=1),10,replace=TRUE)//不存在小数
遇到问题
问题1
g <- graph(c(0,1, 0,2, 1,2, 2,4),n=5)
Error in .Call(“R_igraph_create”, as.numeric(edges) - 1, as.numeric(n), :
At structure_generators.c:84 : Invalid (negative) vertex id, Invalid vertex id解决
Vertices and edge are indexed from one in R igraph, since version 0.6,
so you don’t need the minus ones.
修改成g <- graph(c(1,2, 1,3, 2,3, 3,5),n=5)即可