View source: R/class-network.R
| set_groups | R Documentation |
Assigns node groupings to a cograph_network object. Groups are stored as metadata with a type column ("layer", "cluster", or "group") for use by specialized plot functions.
set_groups(
x,
groups = NULL,
type = c("group", "cluster", "layer"),
nodes = NULL,
layers = NULL,
clusters = NULL
)
x |
A cograph_network object. |
groups |
Node groupings in one of these formats:
|
type |
Group type. One of |
nodes |
Character vector of node labels. Use with |
layers |
Character/factor vector of layer assignments (same length as |
clusters |
Character/factor vector of cluster assignments (same length as |
The modified cograph_network object with node_groups set.
get_groups, splot, detect_communities
# Create network (symmetric for community detection)
mat <- matrix(runif(100), 10, 10)
mat <- (mat + t(mat)) / 2 # Make symmetric (undirected)
diag(mat) <- 0
rownames(mat) <- colnames(mat) <- paste0("N", 1:10)
net <- as_cograph(mat)
# Using vectors (recommended)
net <- set_groups(net,
nodes = paste0("N", 1:10),
layers = c(rep("Macro", 3), rep("Meso", 4), rep("Micro", 3))
)
# Named list -> layers
net <- set_groups(net, list(
Macro = paste0("N", 1:3),
Meso = paste0("N", 4:7),
Micro = paste0("N", 8:10)
), type = "layer")
# Vector -> clusters
net <- set_groups(net, c("A", "A", "A", "B", "B", "B", "C", "C", "C", "C"),
type = "cluster")
# Community detection -> groups
net <- set_groups(net, "louvain", type = "group")
# Data frame with explicit columns
df <- data.frame(nodes = paste0("N", 1:10),
layers = rep(c("Top", "Bottom"), each = 5))
net <- set_groups(net, df)
# Check groups
get_groups(net)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.