Rgexf
Create, read and write GEXF (Graph Exchange XML Format) graph files (used in Gephi and others) in R.
Install / Use
/learn @gvegayon/RgexfREADME
rgexf: Build, Import and Export GEXF Graph Files <img src="man/figures/logo.svg" align="right" height="200"/>
The first R package to work with GEXF graph files (used in Gephi and
others). rgexf allows reading and writing graph files, including:
-
Nodes/edges attributes,
-
GEXF viz attributes (such as color, size, and position),
-
Network dynamics (for both edges and nodes, including spells) and
-
Edges weighting.
Users can build/handle graphs element-by-element or through data-frames, visualize the graph on a web browser through ~~sigmajs javascript~~ gexf-js library and interact with the igraph package.
Changes in rgexf version 0.16.3 (2024-06-27)
- Dynamically loaded components in the Rd files were removed to comply with new CRAN policies.
More in the NEWS.md file.
Installation
To install the latest version of rgexf, you can use devtools
library(devtools)
install_github("gvegayon/rgexf")
The more stable (but old) version of rgexf can be found on CRAN too:
install.packages("rgexf")
Citation
citation(package="rgexf")
To cite rgexf in publications use the following paper:
Vega Yon G (2021). "Building, Importing, and Exporting GEXF Graph
Files with rgexf." _Journal of Open Source Software_, *6*, 3456.
doi:10.21105/joss.03456 <https://doi.org/10.21105/joss.03456>,
<https://doi.org/10.21105/joss.03456>.
And the actual R package:
Vega Yon G, Fábrega Lacoa J, Kunst J (????). _netdiffuseR: Build,
Import and Export GEXF Graph Files_. doi:10.5281/zenodo.5182708
<https://doi.org/10.5281/zenodo.5182708>, R package version 0.16.3,
<https://github.com/gvegayon/rgexf>.
To see these entries in BibTeX format, use 'print(<citation>,
bibtex=TRUE)', 'toBibtex(.)', or set
'options(citation.bibtex.max=999)'.
Examples
Example 1: Importing GEXF files
We can use the read.gexf function to read GEXF files into R:
# Loading the package
library(rgexf)
g <- system.file("gexf-graphs/lesmiserables.gexf", package="rgexf")
g <- read.gexf(g)
head(g) # Taking a look at the first handful
<?xml version="1.0" encoding="UTF-8"?>
<gexf xmlns="http://www.gexf.net/1.3" xmlns:viz="http://www.gexf.net/1.3/viz" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.3" xsi:schemaLocation="http://www.gexf.net/1.3 http://www.gexf.net/1.3/gexf.xsd">
<meta lastmodifieddate="2016-11-09">
<creator>Gephi 0.9</creator>
<description/>
</meta>
<graph defaultedgetype="undirected" mode="static">
<attributes class="node" mode="static">
<attribute id="modularity_class" title="Modularity Class" type="integer"/>
</attributes>
<nodes>
<node id="11" label="Valjean">
<attvalues>
<attvalue for="modularity_class" value="1"/>
</attvalues>
<viz:size value="100.0"/>
<viz:position x="-87.93029" y="6.8120565"/>
<viz:color r="245" g="91" b="91"/>
</node>
<node id="48" label="Gavroche">
<attvalues>
<attvalue for="modularity_class" value="8"/>
</attvalues>
<viz:size value="61.600006"/>
<viz:position x="387.89572" y="-110.462326"/>
<viz:color r="91" g="245" b="91"/>
</node>
<node id="55" label="Marius">
<attvalues>
<attvalue for="modularity_class" value="6"/>
</attvalues>
<viz:size value="53.37143"/>
<viz:position x="206.44687" y="13.805411"/>
<viz:color r="194" g="91" b="245"/>
</node>
<node id="27" label="Javert">
<attvalues>
<attvalue for="modularity_class" value="7"/>
</attvalues>
<viz:size value="47.88571"/>
<viz:position x="-81.46074" y="204.20204"/>
<viz:color r="91" g="245" b="194"/>
</node>
<node id="25" label="Thenardier">
<attvalues>
<attvalue for="modularity_class" value="7"/>
</attvalues>
<viz:size value="45.142853"/>
<viz:position x="82.80825" y="203.1144"/>
<viz:color r="91" g="245" b="194"/>
</node>
<node id="23" label="Fantine">
<attvalues>
<attvalue for="modularity_class" value="2"/>
</attvalues>
<viz:size value="42.4"/>
<viz:position x="-313.42786" y="289.44803"/>
<viz:color r="91" g="194" b="245"/>
</node>
...
</nodes>
<edges>
<edge id="0" source="1" target="0"/>
<edge id="1" source="2" target="0" weight="8.0"/>
<edge id="2" source="3" target="0" weight="10.0"/>
<edge id="3" source="3" target="2" weight="6.0"/>
<edge id="4" source="4" target="0"/>
<edge id="5" source="5" target="0"/>
...
</edges>
</graph>
</gexf>
Moreover, we can use the gexf.to.igraph() function to convert the
gexf object into an igraph object:
library(igraph)
Attaching package: 'igraph'
The following objects are masked from 'package:stats':
decompose, spectrum
The following object is masked from 'package:base':
union
ig <- gexf.to.igraph(g)
op <- par(mai = rep(0, 4)) # Making room
plot(ig)

par(op)
Using the plot.gexf method–which uses the gexf-js JavaScript
library–results in a Web visualization of the graph, like this:
plot(g)

A live version of the figure is available here.
Example 2: Static net
# Creating a group of individuals and their relations
people <- data.frame(matrix(c(1:4, 'juan', 'pedro', 'matthew', 'carlos'),ncol=2))
people
X1 X2
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))
relations
X1 X2
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.3" xmlns:viz="http://www.gexf.net/1.3/viz" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.gexf.net/1.3 http://www.gexf.net/1.3/gexf.xsd" version="1.3">
<meta lastmodifieddate="2024-10-18">
<creator>NodosChile</creator>
<description>A GEXF file written in R with "rgexf"</description>
<keywords>GEXF, NodosChile, R, rgexf, Gephi</keywords>
</meta>
<graph mode="static" defaultedgetype="undirected">
<nodes>
<node id="1" label="juan">
<viz:color r="255" g="99" b="71" a="1"/>
<viz:position x="-250" y="250" z="0"/>
<viz:size value="125"/>
</node>
<node id="2" label="pedro">
<viz:color r="255" g="99" b="71" a="1"/>
<viz:position x="250" y="-250" z="0"/>
<viz:size value="125"/>
</node>
<node id="3" label="matthew">
<viz:color r="255" g="99" b="71" a="1"/>
<viz:position x="63.1149047588788" y="130.10577758682" z="0"/>
<viz:size value="125"/>
</node>
<node id="4" label="carlos">
<viz:color r="255" g="99" b="71" a="1"/>
<viz:position x="58.513361107523" y="223.719394024583" z="0"/>
<viz:size value="125"/>
</node>
</nodes>
<edges>
<edge id="0" source="1" target="4" weight="1"/>
<edge id="1" source="1" target="2" weight="1"/>
<edge id="2" source="1" target="3" weight="1"/>
<edge id="3" source="2" target="3" weight="1"/>
<edge id="4" source="3" target="4" weight="1"/>
<edge id="5" source="4" target="2" weight="1"/>
</edges>
</graph>
</gexf>
Example 3: 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.3" xmlns:viz="http://www.gexf.net/1.3/viz" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.gexf.net/1.3 http://www.gexf.net/1.3/gexf.xsd" version="1.3">
<meta lastmodifieddate="2024-10-18">
<creator>NodosChile</creator>
Related Skills
node-connect
339.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.9kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
339.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.9kCommit, push, and open a PR

