Wiki

Clone wiki

rgexf / Home

WE HAVE MOVED TO https://github.com/gvegayon/rgexf

Downloads

es- en

#rgexf: An R package to build GEXF graph files#

The first R package to work with GEXF graph files (used in Gephi and others). Using XML library, it allows the user to easily build/read graph files including attributes, GEXF viz attributes (such as colour, size, and position), network dynamics (for both edges and nodes, including spells) and edges weighting. Users can build/handle graphs element-by-element or massively through data-frames, visualize the graph on a web browser through sigmajs javascript library and interact with the igraph package.. (Installation)

News

[2015-02-03] Version 0.15.2.3 of rgexf is on CRAN. Just updating emails...

[2014-03-10] Version 0.14.9 of rgexf is on CRAN! solves issues 15-18. Thanks =).

[2013-08-07] Version 0.13.8 of rgexf is on CRAN! New plot.gexf method and igraph integration working =).

[2013-05-09] Version 0.13.05 of rgexf (transitory) solves issues N 9 & 10. Looking forward for the next CRAN version.

[2013-03-14] Version 0.13.03 of rgexf is on its way to CRAN. It now supports working with spells!

[2013-01-04] Version 0.13.01 of rgexf is on its way to CRAN. Significant improvements and new features!

[2012-06-19] Version 0.12.06 of rgexf is on CRAN! Now it can be directly download from R.

[2012-03-29] Version 0.12.03.29 of rgexf has been released including many bug fixes. Please download the lastest version to check it out.

Example 1: Static net

# 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"
# Defining the relations structure
> relations <- data.frame(matrix(c(1,4,1,2,1,3,2,3,3,4,4,2), ncol=2, byrow=T))
     [,1] [,2]
[1,]    1    4
[2,]    1    2
[3,]    1    3
[4,]    2    3
[5,]    3    4
[6,]    4    2
# Getting things done
> write.gexf(people, relations)
<?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="2013-03-22">
    <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="4"/>
      <node id="3" label="3"/>
      <node id="4" label="1"/>
    </nodes>
    <edges>
      <edge id="0" source="1" target="4" weight="1.0"/>
      <edge id="1" source="1" target="2" weight="1.0"/>
      <edge id="2" source="1" target="3" weight="1.0"/>
      <edge id="3" source="2" target="3" weight="1.0"/>
      <edge id="4" source="3" target="4" weight="1.0"/>
      <edge id="5" source="4" target="2" weight="1.0"/>
    </edges>
  </graph>
</gexf>

Example 2: Dynamic net

# Defining the dynamic structure, note that there are some nodes that have NA at the end.
> time<-matrix(c(10.0,13.0,2.0,2.0,12.0,rep(NA,3)), nrow=4, ncol=2)
> time
     [,1] [,2]
[1,]   10   12
[2,]   13   NA
[3,]    2   NA
[4,]    2   NA
# Getting things done
> write.gexf(people, relations, nodeDynamic=time)
<?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">
  <graph mode="dynamic" start="2" end="13" timeformat="double" defaultedgetype="undirected">
    <nodes>
      <node id="1" label="juan" start="10" end="12"/>
      <node id="2" label="pedro" start="13"/>
      <node id="3" label="matthew" start="2"/>
      <node id="4" label="carlos" start="2"/>
    </nodes>
    <edges>
      <edge source="1" target="4"/>
      <edge source="1" target="2"/>
      <edge source="1" target="3"/>
      <edge source="2" target="3"/>
      <edge source="3" target="4"/>
      <edge source="4" target="2"/>
    </edges>
  </graph>
</gexf>

Example 3: More complex... Dynamic graph with attributes both for nodes and edges

First we define dynamics

> time.nodes<-matrix(c(10.0,13.0,2.0,2.0,12.0,rep(NA,3)), nrow=4, ncol=2)
> time.nodes
     [,1] [,2]
[1,]   10   12
[2,]   13   NA
[3,]    2   NA
[4,]    2   NA

> time.edges<-matrix(c(10.0,13.0,2.0,2.0,12.0,1,5,rep(NA,5)), nrow=6, ncol=2)
> time.edges
     [,1] [,2]
[1,]   10    5
[2,]   13   NA
[3,]    2   NA
[4,]    2   NA
[5,]   12   NA
[6,]    1   NA

Now we define the attribute values

# Defining a data frame of attributes for nodes and edges

> node.att <- data.frame(letrafavorita=letters[1:4], numbers=1:4, stringsAsFactors=F)
> node.att
  letrafavorita numbers
1             a       1
2             b       2
3             c       3
4             d       4

> edge.att <- data.frame(letrafavorita=letters[1:6], numbers=1:6, stringsAsFactors=F)
> edge.att
  letrafavorita numbers
1             a       1
2             b       2
3             c       3
4             d       4
5             e       5
6             f       6

# Getting the things done
> write.gexf(nodes=people, edges=relations, edgeDynamic=time.edges, edgesAtt=edge.att,
+      nodeDynamic=time.nodes, nodesAtt=node.att)
<?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">
  <graph mode="dynamic" start="1" end="13" timeformat="double" defaultedgetype="undirected">
    <attributes class="node" mode="static">
      <attribute id="att1" title="letrafavorita" type="string"/>
      <attribute id="att2" title="numbers" type="integer"/>
    </attributes>
    <attributes class="edge" mode="static">
      <attribute id="att1" title="letrafavorita" type="string"/>
      <attribute id="att2" title="numbers" type="integer"/>
    </attributes>
    <nodes>
      <node id="1" label="juan" start="10" end="12">
        <attvalues>
          <attvalue for="att1" value="a"/>
          <attvalue for="att2" value="1"/>
        </attvalues>
      </node>
      <node id="2" label="pedro" start="13">
        <attvalues>
          <attvalue for="att1" value="b"/>
          <attvalue for="att2" value="2"/>
        </attvalues>
      </node>
      <node id="3" label="matthew" start=" 2">
        <attvalues>
          <attvalue for="att1" value="c"/>
          <attvalue for="att2" value="3"/>
        </attvalues>
      </node>
      <node id="4" label="carlos" start=" 2">
        <attvalues>
          <attvalue for="att1" value="d"/>
          <attvalue for="att2" value="4"/>
        </attvalues>
      </node>
    </nodes>
    <edges>
      <edge source="1" target="4" start="10" end=" 5">
        <attvalues>
          <attvalue for="att1" value="a"/>
          <attvalue for="att2" value="1"/>
        </attvalues>
      </edge>
      <edge source="1" target="2" start="13">
        <attvalues>
          <attvalue for="att1" value="b"/>
          <attvalue for="att2" value="2"/>
        </attvalues>
      </edge>
      <edge source="1" target="3" start=" 2">
        <attvalues>
          <attvalue for="att1" value="c"/>
          <attvalue for="att2" value="3"/>
        </attvalues>
      </edge>
      <edge source="2" target="3" start=" 2">
        <attvalues>
          <attvalue for="att1" value="d"/>
          <attvalue for="att2" value="4"/>
        </attvalues>
      </edge>
      <edge source="3" target="4" start="12">
        <attvalues>
          <attvalue for="att1" value="e"/>
          <attvalue for="att2" value="5"/>
        </attvalues>
      </edge>
      <edge source="4" target="2" start=" 1">
        <attvalues>
          <attvalue for="att1" value="f"/>
          <attvalue for="att2" value="6"/>
        </attvalues>
      </edge>
    </edges>
  </graph>
</gexf>

More real-life examples at [[http://www.nodoschile.org/visualizaciones/]]

Updated