Lays out any undirected graph with ForceAtlas2, for example an
SNN graph or a graph from another package. Edge weights come from the
weight edge attribute; without one, every edge weighs 1. Self-loops are
dropped. Only the optimisation parameters in fa2_params are used; the
graph and initialisation ones do not apply here.
Usage
forceatlas2_from_graph(
graph,
init = NULL,
fa2_params = params_fa2(),
seed = 42L,
.verbose = TRUE
)Arguments
- graph
An undirected
igraphobject without multi-edges. Useigraph::as_undirected(mode = "collapse")origraph::simplify()to get there. If present, theweightedge attribute needs to be finite and non-negative.- init
Optional numerical matrix of dimensions
vcount(graph) x 2. The initial layout, e.g. a UMAP of the same samples. IfNULL, a random layout is used. Defaults toNULL.- fa2_params
Named list. ForceAtlas2 parameters, see
params_fa2().- seed
Integer. Random seed for reproducibility. Defaults to
42L.- .verbose
Logical or integer. Controls verbosity.
TRUEor1Lprints timed stages and epochs every 50,2Ladds parameters and the kNN internals,FALSEor0Lis silent. Defaults toTRUE.
Value
A numerical matrix with dimensions vcount(graph) x 2 containing
the ForceAtlas2 layout, rows in vertex order.
Examples
if (requireNamespace("igraph", quietly = TRUE)) {
g <- igraph::sample_gnp(200L, 0.05)
emb <- forceatlas2_from_graph(g, .verbose = FALSE)
dim(emb)
}
#> [1] 200 2
