knitr::opts_chunk$set(fig.path = "man/figures/", warning = FALSE)
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.
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(package="rgexf")
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.
# 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)
# 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)
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)
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
devtools::session_info()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.