Labels do not show in output file

Issue #18 resolved
Tim Smith created an issue

Maybe I'm missing something, but the following code does not produce an output with the proper labels (and, also, an error)

...r code... people <- data.frame(c(1:4), c('juan', 'pedro', 'matthew', 'carlos')) relations <- data.frame(source=c(1,1,1,1), target=c(2,3,4,2)) write.gexf(nodes=people, edges=relations)

..gexf output <?xml version="1.0" encoding="UTF-8"?> <gexf xmlns="http://www.gexf.net/1.2draft" xmlns:viz="http://www.gexf.net/1.1draft/viz" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.gexf.net/1.2draft http://www.gexf.net/1.2draft/gexf.xsd" version="1.2"> <meta lastmodifieddate="2014-03-08"> <creator>NodosChile</creator> <description>A graph file writing in R using "rgexf"</description> <keywords>gexf graph, NodosChile, R, rgexf</keywords> </meta> <graph mode="static"> <nodes> <node id="1" label="2"/> <node id="2" label="2"/> <node id="3" label="2"/> <node id="4" label="2"/> </nodes> <edges> <edge id="0" source="1" target="2" weight="1.0"/> <edge id="1" source="1" target="3" weight="1.0"/> <edge id="2" source="1" target="4" weight="1.0"/> <edge id="3" source="1" target="2" weight="1.0"/> </edges> </graph> </gexf> Warning message: In [<-.data.frame(*tmp*, , tofix, value = list(2, 4, 3, 1)) : provided 4 variables to replace 1 variables

Comments (6)

  1. Ni Ma

    Hi , Tim

    It seems I get the same issue . The Example 1 at Project Home page already contains the problem .

    # Creating a group of individuals and their relations
    > people <- data.frame(matrix(c(1:4, 'juan', 'pedro', 'matthew', 'carlos'),ncol=2))
    > people
         [,1] [,2]    
    [1,] "1"  "juan"  
    [2,] "2"  "pedro" 
    [3,] "3"  "matthew"
    [4,] "4"  "carlos"
    
      <graph mode="static">
        <nodes>
          <node id="1" label="2"/>
          <node id="2" label="4"/>
          <node id="3" label="3"/>
          <node id="4" label="1"/>
        </nodes>
    

    Where the "juan" ?

    It reproduced for me by labels' nodes aren't set properly at GEXF file.

  2. jorgefabrega

    Hi Tim, it seems that your code produce objects of the class factor. Try with:

    people <- data.frame(id=c(1:4), label=c('juan', 'pedro', 'matthew', 'carlos'), stringsAsFactors=F)

    ... it should work as you expected

    Best,

    Jorge

  3. Tim Smith reporter

    Thank you Jorge. You are correct. This was the source of the problem.

    (I wish I had figured this out yesterday, lol. I resorted to writing custom code to export to an excel file for loading into Gephi)

  4. George Vega Yon repo owner

    Several users have got confused with this issue. Please refer to the package manual, specifically to the keepFactors option. For the next version I will set the default option of -keepFactors- as -FALSE-. Either way I will include a warning message whenever factors are used and the

  5. Log in to comment