Question

I have a problem with the R package "rgexf". In particular, I have a problem with the edges of the network I import to Gephi. In R I can produce a database of vertices

>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

and a database of edges (a single edge to be precise)

>edges 
      Source Target
    1      5      9

I create a .gexf file using

  >write.gexf(output = path_gexf, nodes = vertices, edges = edges,  defaultedgetype = "undirected")

where path_gexf is just the path of the output file (which is called example.gexf).
I open example.gexf using Gephi (version 0.8.2 beta). In image 1: enter image description here

you can see the import report in Gephi: the number of vertices and edges is correct; I manually change the graph type to undirected and I import all data to the Data Laboratory window.

  1. Question 1. Why am I supposed to specify "undirected" in the import report window if I already did it in the write.gexf function?

In image2

enter image description here

you can see that, after the import, the type of graph switches automatically to "directed" and no edge is actually imported.

In image 3

enter image description here

we have the list of vertices: all is fine. Labels and Id's are correctly imported. In image 4

enter image description here

you can see the Data Laboratory window for edges: no edge is imported, as already noted in image 2. I really do not understand why no edge is imported.

  1. Question 2. How to correct the import of the example.gexf file? At the level of R code all is smooth, and vertices / edges are correctly generated by my code. Problems occur with Gephi.

Remarks: I have plenty of .gexf files with issues regarding the import of edges; in many cases only few edges are imported with uncorrect "Source" and "Target". Strangely enough, parallel edges are always properly counted according to their multiplicities.

I apologize for the long post.

EDIT: some tests with dummy R code

I did some tests using @James Tobin's code (thanks!). It works fine also on my pc. I did tests with graphs with 2 edges: the tests were all ok. Then I moved to the 3,4 edges cases, using

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")

and

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")

In both cases the XLM code is correct w.r.t. the nodes & edges id's, labels, sources and targets.

Where are the issues? In the 3 edges case the import report in Gephi is correct, while the data laboratory edge window does not show the edge

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

In the 4 edges case the edge

 <edge id="0" source="5" target="2" weight="1.0"/>

is missing, instead.

I start to believe there is a bug in Gephi 0.8.2 and not in my code.

Any suggestion/comment?

Was it helpful?

Solution

Question 1: Even though you already specified the graph as undirected in the gexf file, directed is the default, although clicking it is a little bit annoying, at least its not that big of deal. From a safety perspective, its easier to allow a user to double check what kind of graph they are importing than to potentially select incorrectly. It takes 2 seconds, not that big of a deal.

Question 2: I copied your example

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")

but I don't have any issues with edges. enter image description here enter image description here enter image description here

Perhaps you can include your exact code that fails? Perhaps your edges aren't in data.frame form? Just guessing because I couldn't replicate your error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top