Induced_graph不是图形对象,绘制图形网络

时间:2018-04-13 03:36:38

标签: r igraph

我正在学习如何使用R中的igraph库来绘制图形和网络。

我从此存储库中检索了一个数据集:http://snap.stanford.edu/data/amazon0302.html

我读了图,我计算了节点的程度。该数据集包含超过20k的节点。因此,我想绘制V1列的最多3个节点的子集。

aws_g <- read.table("Amazon0302.txt")
aws <- graph.data.frame(aws_g, directed = T)
# Calculate degree
d <- degree(aws)
aws_g$DegreeV1 <- d[as.character(aws_g$V1)]
aws_g$DegreeV2 <- d[as.character(aws_g$V2)]
dput(aws_g[1:30,])
g2 <- induced_subgraph(aws_g, aws_g[1:7,])
g2
plot(g2)

上面的代码给了我这个错误:

  

indu_subgraph中的错误(aws_g,aws_g [1:7,]):不是图形对象

我想要的输出

小节点和节点的图形具有不同的大小,具体取决于节点的程度。

我无法对图表进行子集化,因此可以绘制图表。

aws_g对象看起来像:

structure(list(V1 = c(0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 
2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 5L, 
5L, 5L, 5L, 5L), V2 = c(1L, 2L, 3L, 4L, 5L, 0L, 2L, 4L, 5L, 15L, 
0L, 11L, 12L, 13L, 14L, 63L, 64L, 65L, 66L, 67L, 7L, 16L, 17L, 
18L, 19L, 6L, 7L, 8L, 9L, 10L), DegreeV1 = c(7, 7, 7, 7, 7, 6, 
6, 6, 6, 6, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 30, 30, 30, 30, 30, 
59, 59, 59, 59, 59), DegreeV2 = c(6, 7, 6, 30, 59, 7, 7, 30, 
59, 26, 7, 58, 34, 40, 18, 59, 10, 13, 12, 23, 39, 11, 26, 177, 
21, 103, 39, 298, 20, 39)), .Names = c("V1", "V2", "DegreeV1", 
"DegreeV2"), row.names = c(NA, 30L), class = "data.frame")

1 个答案:

答案 0 :(得分:1)

啊,你在induced_subgraph内错误地指你的顶点。试试这个:

g2 <- induced_subgraph(aws_g, 1:7)
plot(g2)

enter image description here