Aligns and groups observations based on k-means clustering, enabling observation splits by cluster groups.
align_kmeans(
centers,
...,
data = NULL,
active = NULL,
set_context = deprecated(),
name = deprecated()
)
A "AlignKmeans"
object.
either the number of clusters, say \(k\), or a set of
initial (distinct) cluster centres. If a number, a random set of
(distinct) rows in x
is chosen as the initial centres.
Arguments passed on to stats::kmeans
iter.max
the maximum number of iterations allowed.
nstart
if centers
is a number, how many random sets
should be chosen?
algorithm
character: may be abbreviated. Note that
"Lloyd"
and "Forgy"
are alternative names for one
algorithm.
trace
logical or integer number, currently only used in the
default method ("Hartigan-Wong"
): if positive (or true),
tracing information on the progress of the algorithm is
produced. Higher values may produce more tracing information.
A matrix-like object. By default, it inherits from the layout
matrix
.
A active()
object that defines the context settings when
added to a layout.
It is important to note that we consider rows as observations, meaning
vec_size(data)
/NROW(data)
must match the number of observations along the
axis used for alignment (x-axis for a vertical stack layout, y-axis for a
horizontal stack layout).
quad_layout()
/ggheatmap()
: For column annotation, the layout
matrix
will be transposed before use (if data
is a function, it is
applied to the transposed matrix), as column annotation uses columns as
observations but alignment requires rows.
stack_layout()
: The layout matrix is used as is, aligning all plots
along a single axis.
ggheatmap(matrix(rnorm(81), nrow = 9)) +
anno_top() +
align_kmeans(3L)
Run the code above in your browser using DataLab