% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/class-network.R
\name{set_groups}
\alias{set_groups}
\title{Set Node Groups}
\usage{
set_groups(
  x,
  groups = NULL,
  type = c("group", "cluster", "layer"),
  nodes = NULL,
  layers = NULL,
  clusters = NULL
)
}
\arguments{
\item{x}{A cograph_network object.}

\item{groups}{Node groupings in one of these formats:
\itemize{
\item Character string: Community detection method ("louvain", "walktrap",
"fast_greedy", "label_prop", "infomap", "leiden")
\item Named list: Group name -> node vector mapping
(e.g., \code{list(A = c("N1","N2"), B = c("N3","N4"))})
\item Unnamed vector: Group assignment per node (same order as nodes)
\item Data frame: Must have "node"/"nodes" column plus one of
"layer"/"layers", "cluster"/"clusters", or "group"/"groups"
(plural forms are automatically normalized to singular)
\item NULL: Use \code{nodes} + one of \code{layers}/\code{clusters} vectors
}}

\item{type}{Group type. One of \code{"group"} (default), \code{"cluster"},
or \code{"layer"}. Ignored when using \code{layers} or \code{clusters}
vector arguments since the type is inferred from which argument is provided.}

\item{nodes}{Character vector of node labels. Use with \code{layers}, \code{clusters},
to specify groupings via vectors instead of a data frame.}

\item{layers}{Character/factor vector of layer assignments (same length as \code{nodes}).}

\item{clusters}{Character/factor vector of cluster assignments (same length as \code{nodes}).}
}
\value{
The modified cograph_network object with \code{node_groups} set.
}
\description{
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.
}
\examples{
set.seed(1)
mat <- matrix(runif(100), 10, 10)
mat <- (mat + t(mat)) / 2; diag(mat) <- 0
rownames(mat) <- colnames(mat) <- paste0("N", 1:10)
net <- as_cograph(mat)

# 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")
get_groups(net)
}
\seealso{
\code{\link{get_groups}}, \code{\link{splot}}, \code{\link{detect_communities}}
}
