Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gvegayon/rgexf

Create, read and write GEXF (Graph Exchange XML Format) graph files (used in Gephi and others) in R.
https://github.com/gvegayon/rgexf

gephi gexf gexf-graph-files r rpackage social-network xml

Last synced: about 1 month ago
JSON representation

Create, read and write GEXF (Graph Exchange XML Format) graph files (used in Gephi and others) in R.

Awesome Lists containing this project

README

        

[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/rgexf.png)](https://cran.r-project.org/package=rgexf)
[![Downloads](http://cranlogs.r-pkg.org/badges/rgexf?color=brightgreen.png)](https://cran.r-project.org/package=rgexf)
[![Downloads](https://cranlogs.r-pkg.org/badges/grand-total/rgexf.png)](https://cran.r-project.org/package=rgexf)
[![R
CI](https://github.com/gvegayon/rgexf/actions/workflows/ci.yml/badge.svg)](https://github.com/gvegayon/rgexf/actions/workflows/ci.yml)
[![rgexf
website](https://github.com/gvegayon/rgexf/actions/workflows/website.yml/badge.svg)](https://github.com/gvegayon/rgexf/actions/workflows/website.yml)
[![AppVeyor Build
Status](https://ci.appveyor.com/api/projects/status/github/gvegayon/rgexf?branch=master&svg=true.png)](https://ci.appveyor.com/project/gvegayon/rgexf)
[![Coverage
Status](https://img.shields.io/codecov/c/github/gvegayon/rgexf/master.svg)](https://app.codecov.io/github/gvegayon/rgexf?branch=master)
[![DOI](https://joss.theoj.org/papers/10.21105/joss.03456/status.svg)](https://doi.org/10.21105/joss.03456)
[![Sponsor](https://img.shields.io/badge/-Sponsor-fafbfc?logo=GitHub%20Sponsors.png)](https://github.com/sponsors/gvegayon)

# 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 reading and writing graph files, including:

1. Nodes/edges attributes,

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

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

4. 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](https://github.com/raphv/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](NEWS.md) file.

# Installation

To install the latest version of `rgexf`, you can use `devtools`

``` r
library(devtools)
install_github("gvegayon/rgexf")
```

The more stable (but old) version of `rgexf` can be found on CRAN too:

install.packages("rgexf")

# Citation

``` r
citation(package="rgexf")
```

To cite rgexf in publications use the following paper:

Vega Yon, G. G., (2021). Building, Importing, and Exporting GEXF
Graph Files with rgexf. Journal of Open Source Software, 6(64), 3456,
https://doi.org/10.21105/joss.03456

And the actual R package:

Vega Yon G, Fábrega Lacoa J, Kunst J (2024). _netdiffuseR: Build,
Import and Export GEXF Graph Files_. doi:10.5281/zenodo.5182708
, R package version 0.17.0,
.

To see these entries in BibTeX format, use 'print(,
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:

``` 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
```




Gephi 0.9























































...








...


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

``` r
library(igraph)
```

Attaching package: 'igraph'

The following objects are masked from 'package:stats':

decompose, spectrum

The following object is masked from 'package:base':

union

``` r
ig <- gexf.to.igraph(g)

op <- par(mai = rep(0, 4)) # Making room
plot(ig)
```

![](man/figures/igraph-1.png)

``` r
par(op)
```

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

``` r
plot(g)
```

![](inst/gexf-graphs/lesmiserables.png)

A live version of the figure is available
[here](https://gvegayon.github.io/rgexf/lesmiserables/).

## Example 2: Static net

``` r
# 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

``` r
# 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

``` r
# Getting things done
write.gexf(people, relations)
```




NodosChile
A GEXF file written in R with "rgexf"
GEXF, NodosChile, R, rgexf, Gephi


































## Example 3: Dynamic net

``` r
# 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

``` r
# Getting things done
write.gexf(people, relations, nodeDynamic=time)
```




NodosChile
A GEXF file written in R with "rgexf"
GEXF, NodosChile, R, rgexf, Gephi


































## Example 4: More complex… Dynamic graph with attributes both for nodes and edges

First, we define dynamics

``` r
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

``` r
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

``` r
# 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

``` r
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

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




NodosChile
A GEXF file written in R with "rgexf"
GEXF, NodosChile, R, rgexf, Gephi
























































































# 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](https://github.com/gvegayon/rgexf/issues) so that we can talk
about it.

Please note that the rgexf project is released with a [Contributor Code
of
Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html).
By contributing to this project, you agree to abide by its terms

# Session info

``` r
devtools::session_info()
```

─ Session info ───────────────────────────────────────────────────────────────
setting value
version R version 4.4.0 (2024-04-24)
os Ubuntu 22.04.4 LTS
system x86_64, linux-gnu
ui X11
language (EN)
collate en_US.UTF-8
ctype en_US.UTF-8
tz America/Denver
date 2024-06-30
pandoc 3.1.1 @ /usr/bin/ (via rmarkdown)

─ Packages ───────────────────────────────────────────────────────────────────
package * version date (UTC) lib source
cachem 1.1.0 2024-05-16 [2] RSPM (R 4.4.0)
cli 3.6.2 2023-12-11 [2] RSPM (R 4.3.0)
devtools 2.4.5 2022-10-11 [2] RSPM (R 4.2.0)
digest 0.6.35 2024-03-11 [2] RSPM (R 4.3.0)
ellipsis 0.3.2 2021-04-29 [2] CRAN (R 4.1.1)
evaluate 0.23 2023-11-01 [2] RSPM (R 4.3.0)
fastmap 1.2.0 2024-05-15 [2] RSPM (R 4.4.0)
fs 1.6.4 2024-04-25 [2] RSPM (R 4.3.0)
glue 1.7.0 2024-01-09 [2] RSPM (R 4.3.0)
htmltools 0.5.8.1 2024-04-04 [2] RSPM (R 4.3.0)
htmlwidgets 1.6.4 2023-12-06 [2] RSPM (R 4.3.0)
httpuv 1.6.15 2024-03-26 [2] RSPM (R 4.3.0)
igraph * 2.0.3 2024-03-13 [1] CRAN (R 4.4.0)
jsonlite 1.8.8 2023-12-04 [2] RSPM (R 4.3.0)
knitr 1.47 2024-05-29 [2] RSPM (R 4.4.0)
later 1.3.2 2023-12-06 [2] RSPM (R 4.3.0)
lifecycle 1.0.4 2023-11-07 [2] RSPM (R 4.3.0)
magrittr 2.0.3 2022-03-30 [2] RSPM (R 4.2.0)
memoise 2.0.1 2021-11-26 [2] RSPM (R 4.2.0)
mime 0.12 2021-09-28 [2] RSPM (R 4.2.0)
miniUI 0.1.1.1 2018-05-18 [2] CRAN (R 4.0.1)
pkgbuild 1.4.4 2024-03-17 [2] RSPM (R 4.3.0)
pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 4.0.1)
pkgload 1.3.4 2024-01-16 [2] RSPM (R 4.3.2)
profvis 0.3.8 2023-05-02 [2] RSPM (R 4.2.0)
promises 1.3.0 2024-04-05 [2] RSPM (R 4.3.0)
purrr 1.0.2 2023-08-10 [2] RSPM (R 4.2.0)
R6 2.5.1 2021-08-19 [2] RSPM (R 4.2.0)
Rcpp 1.0.12 2024-01-09 [2] RSPM (R 4.3.0)
remotes 2.5.0 2024-03-17 [2] RSPM (R 4.3.0)
rgexf * 0.17.0 2024-06-27 [1] local
rlang 1.1.3 2024-01-10 [2] RSPM (R 4.3.0)
rmarkdown 2.27 2024-05-17 [2] RSPM (R 4.4.0)
servr 0.30 2024-03-23 [2] RSPM (R 4.3.0)
sessioninfo 1.2.2 2021-12-06 [2] RSPM (R 4.2.0)
shiny 1.8.1.1 2024-04-02 [2] RSPM (R 4.3.0)
stringi 1.8.4 2024-05-06 [2] RSPM (R 4.4.0)
stringr 1.5.1 2023-11-14 [2] RSPM (R 4.3.0)
urlchecker 1.0.1 2021-11-30 [2] RSPM (R 4.2.0)
usethis 2.2.3 2024-02-19 [2] RSPM (R 4.3.0)
vctrs 0.6.5 2023-12-01 [2] RSPM (R 4.3.0)
xfun 0.44 2024-05-15 [2] RSPM (R 4.4.0)
XML 3.99-0.16.1 2024-01-22 [2] RSPM (R 4.3.0)
xtable 1.8-4 2019-04-21 [2] CRAN (R 4.0.1)
yaml 2.3.8 2023-12-11 [2] RSPM (R 4.3.0)

[1] /usr/local/lib/R/site-library
[2] /usr/lib/R/site-library
[3] /usr/lib/R/library

──────────────────────────────────────────────────────────────────────────────