【发布时间】:2018-04-13 03:36:37
【问题描述】:
我正在学习如何使用 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)
上面的代码给了我这个错误:
induced_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")
【问题讨论】:
-
aws_g 如何成为graph.data.frame?您将 aws 设为 graph.data.frame 但不是 aws_g。
-
你是对的,是我的错误。我已经更新了我的帖子。