| sn_layout | R Documentation |
Apply a layout algorithm to compute node positions.
sn_layout(network, layout, seed = 42, ...)
network |
A cograph_network object, matrix, data.frame, or igraph object. Matrices and other inputs are auto-converted. |
layout |
Layout algorithm name or a CographLayout object. |
seed |
Random seed for deterministic layouts. Default 42. Set NULL for random. |
... |
Additional arguments passed to the layout function. |
Force-directed layout (Fruchterman-Reingold style). Good general-purpose layout. Default.
Nodes arranged in a circle. Good for small networks or when structure is less important.
Circular layout with grouped nodes clustered together.
Nodes in a regular grid.
Random positions. Useful as starting point.
Central node with others arranged around it.
Two-column layout for bipartite networks.
Two-letter codes for igraph layouts: "kk" (Kamada-Kawai), "fr" (Fruchterman-Reingold), "drl", "mds", "ni" (nicely), "tr" (tree), "ci" (circle), etc.
You can also pass igraph layout functions directly or use full names like "layout_with_kk".
Modified cograph_network object.
cograph for network creation,
sn_nodes for node customization,
sn_edges for edge customization,
sn_theme for visual themes,
splot and soplot for plotting
adj <- matrix(c(0, 1, 1, 1, 0, 1, 1, 1, 0), nrow = 3)
# Built-in layouts
cograph(adj) |> sn_layout("circle") |> splot()
cograph(adj) |> sn_layout("spring") |> splot()
# igraph layouts (if igraph installed)
if (requireNamespace("igraph", quietly = TRUE)) {
cograph(adj) |> sn_layout("kk") |> splot()
cograph(adj) |> sn_layout("fr") |> splot()
}
# Custom coordinates
coords <- matrix(c(0, 0, 1, 0, 0.5, 1), ncol = 2, byrow = TRUE)
cograph(adj) |> sn_layout(coords) |> splot()
# Direct matrix input (auto-converts)
adj |> sn_layout("circle")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.