R& Gephi:使用rgexf包未正确导入网络中的边缘

时间:2014-02-25 21:30:08

标签: r data-visualization gephi

我对R包"rgexf"有疑问。特别是,我有一个问题,我导入到Gephi的网络的边缘。在R中,我可以生成顶点数据库

>vertices
   Id Label
1   1     1
2   2     2
3   3     3
4   4     4
5   5     5
6   6     6
7   7     7
8   8     8
9   9     9
10 10    10

和边缘数据库(准确的单边)

>edges 
      Source Target
    1      5      9

我使用

创建一个.gexf文件
  >write.gexf(output = path_gexf, nodes = vertices, edges = edges,  defaultedgetype = "undirected")

其中path_gexf只是输出文件的路径(称为example.gexf) 我使用Gephi(版本0.8.2 beta)打开example.gexf。 在图1中: enter image description here

你可以在Gephi中看到导入报告:顶点和边的数量是正确的;我手动将图表类型更改为无向,并将所有数据导入Data Laboratory窗口。

  1. 问题1 如果我已经在write.gexf函数中执行了这个操作,为什么我应该在导入报告窗口中指定“无向”?
  2. 在image2中

    enter image description here

    您可以看到,导入后,图表类型会自动切换为“定向”,实际上不会导入任何边缘。

    在图片3中

    enter image description here

    我们有顶点列表:一切都很好。正确导入标签和标识。在图像4

    enter image description here

    您可以看到数据实验室窗口的边缘:没有导入边缘,如图2中所示。我真的不明白为什么没有导入边缘。

    1. 问题2.如何更正example.gexf文件的导入?在R代码级别,所有都是平滑的,并且我的代码正确生成顶点/边。 Gephi出现问题。
    2. 备注:我有很多.gexf文件,有关边缘导入的问题;在许多情况下,只有少数边缘导入了不正确的“源”和“目标”。奇怪的是,平行边缘总是根据其多重性正确计算。

      我为长篇大论道歉。

      编辑:使用虚拟R代码的一些测试

      我使用@James Tobin的代码进行了一些测试(谢谢!)。它也适用于我的电脑。 我用带有2条边的图进行了测试:测试都没问题。 然后我使用

      移动到3,4边缘的情况
      require(rgexf)
      vertices <- as.data.frame(cbind(seq(1,10),seq(1,10)))
      colnames(vertices) <- c('Id','Label')
      edges <- as.data.frame(cbind(c(5,1,2),c(1,1,3)))
      colnames(edges) <- c('Source','Target')
      write.gexf(nodes=vertices,edges=edges,
                 defaultedgetype = "undirected")
      

      require(rgexf)
      vertices <- as.data.frame(cbind(seq(1,10),seq(1,10)))
      colnames(vertices) <- c('Id','Label')
      edges <- as.data.frame(cbind(c(5,1,4,2),c(2,3,1,2)))
      colnames(edges) <- c('Source','Target')
      write.gexf(nodes=vertices,edges=edges,
                 defaultedgetype = "undirected")
      

      在这两种情况下,XLM代码都是正确的w.r.t.节点和边缘ID,标签,来源和目标。

      问题在哪里?在3边缘的情况下,Gephi中的导入报告是正确的,而数据实验室边缘窗口没有显示边缘

      <edge id="1" source="1" target="1" weight="1.0"/>
      

      在4边缘的情况下边缘

       <edge id="0" source="5" target="2" weight="1.0"/>
      
      相反,缺少

      我开始相信Gephi 0.8.2中存在一个错误,而不是我的代码中的错误。

      有任何建议/评论吗?

1 个答案:

答案 0 :(得分:3)

问题1:即使您已经将图表指定为gexf文件中的无向图,但默认是定向的,虽然点击它有点烦人,至少它不是那么大的交易。从安全角度来看,更容易让用户仔细检查他们导入的图表类型,而不是错误地选择。这需要2秒钟,而不是那么大的交易。

问题2:我复制了你的例子

require(rgexf)
vertices <- as.data.frame(cbind(seq(1,10),seq(1,10)))
colnames(vertices) <- c('Id','Label')
edges <- as.data.frame(cbind(5,9))
colnames(edges) <- c('Source','Target')
write.gexf(output='testgex.gexf',nodes=vertices,edges=edges,
          defaultedgetype = "undirected")

但边缘没有任何问题。 enter image description here enter image description here enter image description here

也许您可以包含失败的确切代码?也许你的边缘不是data.frame形式?只是猜测,因为我无法复制你的错误。