3

I'm trying to write a graph to a file but I'm getting a different node labels than I would like.

Example Code:

g <- graph.star(2)
V(g)$name <- c('homer','marge')
write.graph(g,file = 'g.graphml',format = 'graphml')

Output:

<?xml version="1.0" encoding="UTF-8"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
         http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
<!-- Created by igraph -->
  <key id="g_name" for="graph" attr.name="name" attr.type="string"/>
  <key id="g_mode" for="graph" attr.name="mode" attr.type="string"/>
  <key id="g_center" for="graph" attr.name="center" attr.type="double"/>
  <key id="v_name" for="node" attr.name="name" attr.type="string"/>
  <graph id="G" edgedefault="directed">
    <data key="g_name">In-star</data>
    <data key="g_mode">in</data>
    <data key="g_center">1</data>
    <node id="n0">                      ###### This should <node id = "homer">
      <data key="v_name">homer</data>
     </node>
     <node id="n1">                     ###### This should <node id = "marge">
      <data key="v_name">marge</data>
     </node>
     <edge source="n1" target="n0"> 
     </edge>
  </graph>
</graphml>  

I would like the "node id" attribute to be the names of the nodes (as shown in comments). Anybody have any ideas? Thanks!

Gabor Csardi
  • 10,705
  • 1
  • 36
  • 53
MagicScout
  • 105
  • 4
  • AFAIK the "node ID" attribute cannot be the name of the node because there is no guarantee that the IDs you supply are suitable IDs in the GraphML format. The GraphML DTD specifies type `#IDREF` for the `id` attribute, and certain characters are disallowed in `#IDREF`s in an XML file. – Tamás Jul 24 '14 at 13:39
  • OK, thanks! I saw the comment on the GitHub issue as well. – MagicScout Jul 24 '14 at 14:30

1 Answers1

0

You can't do this currently AFAIK. I am not sure why it is not implemented that way. Can you please open an issue about it at https://github.com/igraph/igraph/issues?state=open ? Thanks.

Gabor Csardi
  • 10,705
  • 1
  • 36
  • 53