How to rename igraph node id when writing to file

让人想犯罪 __ 提交于 2019-12-10 22:58:10

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/24934144/how-to-rename-igraph-node-id-when-writing-to-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!