【问题标题】:Plotting graph from adjacency matrix从邻接矩阵绘制图
【发布时间】:2014-02-11 13:47:01
【问题描述】:

我有一个邻接矩阵格式的图:

https://dl.dropboxusercontent.com/u/22681355/network.csv

第一列的节点与第二列的对应节点相连。

是否可以将此图表转换为可以可视化的格式?

【问题讨论】:

  • 我从您的链接中收到 404 错误
  • 你看过这里吗? mlpost.lri.fr/examples/tree.ml.html
  • 检查不同布局的编辑
  • 这不是邻接矩阵。另外请尽量在帖子中包含数据,因为链接将在一年后失效。
  • 是的,链接已经失效了。真是个惊喜。 :)

标签: r graph igraph


【解决方案1】:

试试这个:

 #use igraph for example
 library(igraph)

 #get your data into x
 x <- read.table("~/Downloads/network.csv", sep=";", quote="\"")
 x <- as.matrix(x)
 a <- numeric(0)
 for(i in 1:nrow(x)){
   a <- c(a, x[i,])
 }

 #plot it
 b <- graph(a)
 plot.igraph(b, edge.arrow.size=0.05, vertex.size = 5, vertex.label.cex = 0.5)
 #or tree
 plot.igraph(b, layout=layout.reingold.tilford, edge.arrow.size=0.05, vertex.size = 5, vertex.label.cex = 0.5)
 #or circle
 plot.igraph(b, layout=layout.circle, edge.arrow.size=0.05, vertex.size = 5, vertex.label.cex = 0.5)

【讨论】:

  • a &lt;- c(a, x[i,]) 是 R 中的一种反模式。它使运行时间成为二次方。您可以只说 b &lt;- graph(t(a)) 而没有 for 循环。
  • 该答案的数据不再可用
【解决方案2】:

这不是一个邻接矩阵,而是一个边列表。这是导入和绘制它的简单方法:

csv <- read.csv("http://dl.dropboxusercontent.com/u/22681355/network.csv", sep=";")
g <- graph.data.frame(csv)             
plot(g)

如果您想真正看到绘图上的内容,则需要编辑绘图参数,阅读?igraph.plotting

【讨论】:

    猜你喜欢
    • 2015-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多