% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/R-neighbourhood.R
\name{count_inlaid}
\alias{count_inlaid}
\title{Count inlaid composition within a source cluster}
\usage{
count_inlaid(df, cluster, inlaid_col = "cluster", cluster_col = "cluster")
}
\arguments{
\item{df}{A data.frame containing at least the columns `x`, `y`, cluster
identifier column, and `spot_id`.
  - `x`, `y`: numeric coordinates of spots
- cluster column (name specified by `cluster_col`): cluster assignment for
each spot
- inlaid column (name specified by `inlaid_col`): inlaid/annotation for each
spot
  - `spot_id`: unique identifier for each spot}

\item{cluster}{The cluster label to analyze inlaid composition for.}

\item{inlaid_col}{Character. Name of the column containing inlaid/annotation
values.
Default is `"cluster"` (to analyze cluster composition within another
grouping).}

\item{cluster_col}{Character. Name of the column containing cluster
assignments.
  Default is `"cluster"`.}
}
\value{
A data.frame with columns:
\describe{
  \item{inlaid}{Inlaid/annotation value.}
  \item{count}{Number of spots with this inlaid type in the cluster.}
\item{proportion}{Proportion of this inlaid type among all spots in cluster.}
}
Rows are sorted by count in descending order.
}
\description{
This function counts the composition of an inlaid/annotation column within
a target source cluster. Unlike [count_neighborhood()], this counts types
*inside* the source cluster itself, not around it.
}
\examples{
data("visium_simulated_spe", package = "Battlefield")
spe <- visium_simulated_spe
df <- data.frame(
  spot_id = colnames(spe),
  x = SpatialExperiment::spatialCoords(spe)[, 1],
  y = SpatialExperiment::spatialCoords(spe)[, 2],
  cluster = SummarizedExperiment::colData(spe)$cluster,
inlaid = sample(paste0("type_", 1:3), length(colnames(spe)), replace = TRUE)
)
# Count inlaid types within cluster 1
inlaid_counts <- count_inlaid(df, cluster = 1, inlaid_col = "inlaid")
inlaid_counts

}
