View source: R/class-network.R
| as_cograph | R Documentation |
Creates a lightweight cograph_network object from various network inputs.
The resulting object is a named list with all data accessible via $.
as_cograph(x, directed = NULL, simplify = FALSE, ...)
to_cograph(x, directed = NULL, ...)
x |
Network input. Can be:
|
directed |
Logical. Force directed interpretation. NULL for auto-detect. |
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 (currently unused). |
The cograph_network format is designed to be:
Lean: Only essential data stored, computed values derived on demand
Modern: Uses named list elements instead of attributes for clean $ access
Compatible: Works seamlessly with splot() and other cograph functions
Use getter functions for programmatic access:
get_nodes, get_edges, get_labels,
n_nodes, n_edges
Use setter functions to modify:
set_nodes, set_edges, set_layout
A cograph_network object: a named list with components:
nodesData frame with id, label, (x, y if layout applied)
edgesData frame with from, to, weight columns
directedLogical indicating if network is directed
weightsFull n×n weight matrix (for to_matrix round-trip)
dataOriginal estimation data (sequence matrix, edge list, etc.), or NULL
metaConsolidated metadata list with sub-fields:
source (input type string),
layout (layout info list or NULL),
tna (TNA metadata or NULL)
node_groupsOptional node groupings data frame
A cograph_network object. See as_cograph.
get_nodes to extract the nodes data frame,
get_edges to extract edges as a data frame,
n_nodes and n_edges for counts,
is_directed to check directedness,
splot for plotting
# From adjacency matrix
mat <- matrix(c(0, 1, 1, 1, 0, 1, 1, 1, 0), nrow = 3)
net <- as_cograph(mat)
# Direct $ access to core data
net$nodes # nodes data frame
net$edges # edges data frame
net$directed # TRUE/FALSE
# Getter functions (recommended for programmatic use)
get_nodes(net) # nodes data frame
get_edges(net) # edges data frame (from, to, weight)
get_labels(net) # character vector of labels
n_nodes(net) # 3
n_edges(net) # 3
cograph::is_directed(net) # FALSE (symmetric matrix)
# Setter functions
net <- set_nodes(net, data.frame(id = 1:3, label = c("A", "B", "C")))
net <- set_edges(net, data.frame(from = c(1,2), to = c(2,3), weight = c(0.5, 0.8)))
net <- set_layout(net, data.frame(x = c(0, 1, 0.5), y = c(0, 0, 1)))
# Plot it
splot(net)
# From igraph (if installed)
if (requireNamespace("igraph", quietly = TRUE)) {
g <- igraph::make_ring(10)
net <- as_cograph(g)
splot(net)
}
mat <- matrix(c(0, 1, 1, 1, 0, 1, 1, 1, 0), nrow = 3)
net <- to_cograph(mat)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.