knitr::opts_chunk$set(fig.path = "man/figures/", warning = FALSE)

CRAN_Status_Badge Downloads Downloads R CI rgexf website AppVeyor Build Status Coverage Status DOI Sponsor

rgexf: Build, Import and Export GEXF Graph Files

The first R package to work with GEXF graph files (used in Gephi and others). rgexf allows the user to quickly build/read graph files, including:

a. Nodes/edges attributes,

b. GEXF viz attributes (such as color, size, and position),

c. Network dynamics (for both edges and nodes, including spells), and

d. 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.

x <- readLines("NEWS.md")
ids <- which(grepl("^#\\s*[a-zA-Z]",x))
ids <- ids[1:2] - c(0, 1)
cat(x[ids[1]:ids[2]], sep = "\n")

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")

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

Moreover, we can use the gexf.to.igraph() function to convert the gexf object into an igraph object:

library(igraph)
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)

An 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
# 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
# Getting things done
write.gexf(people, relations)

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
# Getting things done
write.gexf(people, relations, nodeDynamic=time)

Example 4: 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

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

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

edge.att <- data.frame(letrafavorita=letters[1:6], numbers=1:6, stringsAsFactors=F)
edge.att

# Getting the things done
write.gexf(nodes=people, edges=relations, edgeDynamic=time.edges,
           edgesAtt=edge.att, nodeDynamic=time.nodes, nodesAtt=node.att)

Code of Conduct

We welcome contributions to rgexf. Whether reporting a bug, starting a discussion by asking a question, or proposing/requesting a new feature, please go by creating a new issue here so that we can talk about it.

Please note that the rgexf project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms

Session info

devtools::session_info()


gvegayon/rgexf documentation built on June 4, 2023, 3:46 p.m.