Wiki
Clone wikirgexf / es / Home
es - en
rgexf: Un paquete de R para armar archivos de grafos GEXF
El primer paquete de R en trabajar con archivos de grafo GEXF (utilizado en Gephi y otros). Utilizando la librería XML, permite al usuario leer/construir archivos de grafo de manera sencilla incluyendo, atributos, atributos visuales GEXF (tales como color, tamaño y posición), dinámicas de redes (para nodos y conexiones, incluyendo spells) y links ponderados. Los usuarios pueden construir/manipular grafos elemento-por-elemento or de manera masiva a través de data-frames, visualizar los grafos en web usando sigmajs (javascript) e interactuar con el paquete igraph. (Instalación)
Noticias
[2014-03-10] La versión 0.14.9 de rgexf está en CRAN. Resuelve los problemas 15 al 18.
[2013-05-09] La versión 0.13.05 de rgexf (transitoria) resuelve los problemas N 9 & 10. Se viene la próxima versión de CRAN.
[2013-03-14] La versión 0.13.14 de rgexf está en CRAN. Ahora soporta trabajar con spells!
[2013-01-04] La versión 0.13.01 de rgexf está en camino a CRAN. Mejoras significativas y nuevas capacidades!
[2012-06-19] La versión 0.12.06 de rgexf está en CRAN! Ahora puede ser descargada directamente desde R.
[2012-03-29] La versión 0.12.03.29 de rgexf ha sido lanzada incluyendo varias correcciones en el código. Por favor descargue la última versión para ver los cambios.
Ejemplo 1: Grafo estático
# Armando un grupo de individuos (matriz de nodos)
> people <- 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"
# Definiendo las relaciones
> relations <- 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
# Red simple
> 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">
<graph mode="static">
<nodes>
<node id="1" label="juan"/>
<node id="2" label="pedro"/>
<node id="3" label="matthew"/>
<node id="4" label="carlos"/>
</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>
Ejemplo 2: Red dinámica
# Definiendo estructura dinámica, notar que algunos nodos "no terminan" (NA).
> 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
# Armando un grafo dinámico
> 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>
Ejemplo 3: Más complejo... Un grafo dinámico con atributos para nodos y vértices
Primero definimos los valores dinámicos
> 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
Ahora los atributos
# Definiendo Dataframes de atributos para nodos y 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
# Armando el grafo
> 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>
Más ejemplos de la vida real en http://www.nodoschile.org/visualizaciones/
Updated