R/Rcpp implementation of Gephi's ForceAtlas2 graph layout algorithm.
Detailed discussion of the algorithm and its parameters can be found in Jacomy M, Venturini T, Heymann S, Bastian M (2014) ForceAtlas2, a Continuous Graph Layout Algorithm for Handy Network Visualization Designed for the Gephi Software. PLoS ONE 9(6): e98679.
This implementation has been written from scratch in C++ using Eigen for all numerical computations, but is otherwise a more or less direct translation of the original Java implementation found in Gephi's Layout Plugin.
All functions are implemented serially, porting to RcppParallel is planned but not implemented yet.
#install.packages( 'devtools' )
install_github( "jtatria/Rforceatlas" )The package is loaded as usual with
require( Rforceatlas )This will export the following functions:
forceatlasis the actual algorithm implementation in C++.forceatlas_liveis a simple R wrapper allowing for plotting intermediate convergence steps (mimicking Gephi's original implementation). For now, plotting intermediate results interrupts the convergence process, interfering with FA2's adaptive speed feature; results will be slightly different to a full un-interrupted run.layout_with_fa2,with_fa2,layout.forceatlas2are igraph compatibility functions that take igraph objects as inputs.
A brief review of the main algorithm parameters can be found in the exported function's documentation.
Both forceatlas and forceatlas_live take an adjacency matrix as input and return a matrix of
vertex positions in the requested dimensions.
igraph functions take igraph graph objects as inputs and extract the adjacency matrix before calling the main work function.
Typical usage:
require( Rforceatlas )
m <- matrix( ( runif( 100*100 ) > .3 ) * 1, 100, 100 )
lo <- forceatlas( m )
plot( lo )
require( igraph )
g <- sample_grg( 100, .3 )
lo <- layout_with_fa2( g )
plot( g, layout=lo )
require( cairoDevice )
g <- as.undirected( sample_pa( 500 ) )
# base graphics is too slow.
m <- forceatlas_live( device=cairodDevice::Cairo )
# watch the pretty pcitures.J. T. Atria (jtatria@gmail.com)
LGPL v3 or later.