使用igraph获得图形数据集的不清晰图形

时间:2018-04-13 16:14:37

标签: r igraph

我正在尝试将使用igraph从snap.stanford.edu下载的图表数据集可视化。这是我做的:

library(igraph)

graph_file = '4.txt'
#Read the data in using igraph
glist<-read.table(graph_file)
gframe <- graph.data.frame(as.data.frame(glist))
plot(gframe)

从上面的代码生成的图是多层的,不可能从中看到任何东西。看起来像: enter image description here

我有什么遗失的东西吗?有没有办法可以直观地改进这个图表?

图表数据集在我上面提到的链接中。

1 个答案:

答案 0 :(得分:1)

通常使用k-core分解,您可以绘制彼此最紧密连接的节点的子集,并且在能够看到结构的重要元素方面有很大帮助。对于这个数据集,不是那么多,但这里是如何完成整个过程:

> library(igraph)
> con <- gzcon(url("http://snap.stanford.edu/data/p2p-Gnutella04.txt.gz"))
> txt <- readLines(con)
> edgelist <- strsplit(txt[5:39998],"\t")
> m <- matrix(unlist(edgelist),nc=2,byrow=TRUE)
> g <- graph.data.frame(m)
> coreness <- graph.coreness(g)

查找最大连接数:

> max(V(g)$core)
[1] 7

然后绘制:

> kcore <- induced.subgraph(graph=g,vids=which(coreness>6))
> plot(kcore)

呸:

still terrible

在特定节点周围绘制自我网络:

> g3109 <- make_ego_graph(g, 1, "3109")
> plot(g3109[[1]], asp=0)

igraph better