Lays out a graph with a from-scratch Fruchterman-Reingold force simulation (repulsion between all nodes, attraction along edges, with a cooling schedule) and draws nodes and edges in one unified grammar — node and edge aesthetics come from the same aes().

geom_network(
  mapping = NULL,
  data = NULL,
  node_size = NULL,
  edge_color = NULL,
  edge_width = NULL,
  label = TRUE,
  label_size = NULL,
  alpha = NULL,
  iterations = 200,
  seed = 1
)

Arguments

mapping, data

Standard layer overrides. Requires x (source node) and xend (target node); optional size weights the edges.

node_size

Node radius in px.

edge_color, edge_width

Edge appearance.

label, label_size

Node labels.

alpha

Node opacity.

iterations

Force-simulation steps; more is slower but tidier.

seed

Random seed for the initial layout, so plots reproduce.

Value

A Layer to add with +.

Examples

d <- data.frame(
  from = c("A", "A", "B", "C", "D", "E"),
  to = c("B", "C", "C", "D", "E", "A")
)
ggnext(d, aes(x = from, xend = to)) + geom_network() + theme_void()
#> <ggnext plot>
#>   data:  6 x 2
#>   aes:   x = from, xend = to
#>   layers: 1 
#>   coord: cartesian
#>   mode:  static