layout.forceatlas2: Apply ForceAtlas2 layout to a graph

View source: R/ForceAtlas2.R

layout.forceatlas2R Documentation

Apply ForceAtlas2 layout to a graph

Description

This function applies Jacomy et al. (2014)'s 'ForceAtlas2' layout algorithm to an igraph object.

Usage

layout.forceatlas2(
  g,
  iterations = 100,
  linlog = FALSE,
  pos = NULL,
  gravity = 1,
  center = NULL,
  plotstep = 10,
  plotlabels = TRUE,
  scalingratio = 10,
  stronggravity = FALSE,
  jittertol = 1
)

Arguments

g

An igraph object representing the graph.

iterations

Integer. The number of iterations to run the algorithm. Default is 100.

linlog

Logical. If linlog = TRUE, uses the Noack LinLog model implemented for ‘Gephi’ to calculate attractive and repulsive forces (see Noack 2009). Default is linlog = FALSE.

pos

A 2-column matrix of initial positions, where the columns contain x-coordinates and y-coordinates, respectively. If pos = NULL, positions for the first iteration are generated randomly. Default is pos = NULL.

gravity

Numeric. The strength of the gravity force. Default is 1. Note that this is only included in calculations if stronggravity = TRUE. Higher gravity values result in tighter networks.

center

A numeric vector of length 2 specifying the center of gravity. If center = NULL, the center is calculated automatically. Default is center = NULL.

plotstep

Integer. The number of iterations between plots. If plotstep = 0, no plotting is done. Default is plotstep = 10. These plots appear as intermediate output in the console.

plotlabels

Logical. If plotlabels = TRUE, plot node labels appear during the intermediate plotstep graphs. Default is plotlabels = TRUE.

scalingratio

Numeric. The scaling ratio of the layout. Default is 10, in line with ‘Gephi’.

stronggravity

Logical. If stronggravity = TRUE, gravity will be an additional force acting on each node, and the gravity parameter kicks in. Default is stronggravity = FALSE.

jittertol

Numeric. The tolerance for jittering nodes. Default is jittertol = 1; Jacomy et al. (2014) do not recommend increasing it above 1.

Details

This function implements Jacomy et al. (2014)'s ForceAtlas2 layout algorithm on an igraph object. It can handle large graphs and is particularly suitable for visualizing networks. It also includes LinLog mode and a stronger gravity feature, like ‘Gephi’.

Value

A matrix of node positions.

References

\insertRef

jacomy_forceatlas2_2014GephiForR
\insertRefnoack_modularity_2009GephiForR

Examples

# Create a random graph
library(igraph)
g <- erdos.renyi.game(100, 0.05)

# Assign non-numeric row names
V(g)$name <- paste0("node", 1:vcount(g))

# Apply ForceAtlas2 layout
pos <- layout.forceatlas2(g, linlog = TRUE, iterations = 100, scalingratio = 10)
plot(g, layout = pos)


GephiForR documentation built on Sept. 11, 2024, 8:05 p.m.