| cograph | R Documentation |
The main entry point for cograph. Accepts adjacency matrices, edge lists, igraph, statnet network, qgraph, or tna objects and creates a visualization-ready network object.
cograph(
input,
layout = NULL,
directed = NULL,
nodes = NULL,
seed = 42,
simplify = FALSE,
...
)
input |
Network input. Can be:
|
layout |
Layout algorithm: "circle", "spring", "groups", "grid", "random", "star", "bipartite", or "custom". Default NULL (no layout computed). Set to a layout name to compute immediately, or use sn_layout() later. |
directed |
Logical. Force directed interpretation. NULL for auto-detect. |
nodes |
Node metadata. Can be NULL or a data frame with node attributes.
If data frame has a |
seed |
Random seed for deterministic layouts. Default 42. Set NULL for random. |
simplify |
Logical or character. If FALSE (default), every transition from tna sequence data is a separate edge. If TRUE or a string ("sum", "mean", "max", "min"), duplicate edges are aggregated. |
... |
Additional arguments passed to the layout function. |
A cograph_network object that can be further customized and rendered.
splot for base R graphics rendering,
soplot for grid graphics rendering,
sn_nodes for node customization,
sn_edges for edge customization,
sn_layout for changing layouts,
sn_theme for visual themes,
sn_palette for color palettes,
from_qgraph and from_tna for converting external objects
# From adjacency matrix (no layout computed yet - fast!)
adj <- matrix(c(0, 1, 1, 1, 0, 1, 1, 1, 0), nrow = 3)
net <- cograph(adj)
# Layout computed automatically when plotting
splot(net) # Uses spring layout by default
# From edge list
edges <- data.frame(from = c(1, 1, 2), to = c(2, 3, 3))
cograph(edges)
# Compute layout immediately if needed
cograph(adj, layout = "circle") |> splot()
# With customization (pipe-friendly workflow)
adj <- matrix(c(0, 1, 1, 1, 0, 1, 1, 1, 0), nrow = 3)
cograph(adj) |>
sn_nodes(fill = "steelblue") |>
sn_edges(color = "gray50") |>
splot(layout = "circle")
# Weighted network with automatic styling
w_adj <- matrix(c(0, 0.5, -0.3, 0.5, 0, 0.4, -0.3, 0.4, 0), nrow = 3)
cograph(w_adj) |>
sn_edges(color = "weight", width = "weight") |>
splot()
# With igraph (if installed)
if (requireNamespace("igraph", quietly = TRUE)) {
g <- igraph::make_ring(10)
cograph(g) |> splot()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.