A pure-R implementation of the Fruchterman-Reingold force-directed layout,
so geom_sketch_node() / geom_sketch_edge() can place a network with no
external graph dependency. Repulsive forces push every node apart; attractive
forces pull edge-connected nodes together; a cooling schedule settles the
system. Coordinates are returned rescaled to roughly [-1, 1] on both axes.
A data frame with columns x and y, one row per node in index
order.
Arguments
edges
A two-column matrix or data frame of 1-based integer node
indices, one row per edge (from, to). May have zero rows (an
edgeless graph, laid out on a circle).
n_nodes
Number of nodes. Defaults to the largest index in edges
(so isolated high-index nodes need this set explicitly).
niter
Number of iterations. Default 500.
seed
Integer seed for the initial placement. NULL uses
getOption("ggsketch.seed", 1L). The layout is otherwise deterministic.