% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/craft-align-order2.R
\name{align_order2}
\alias{align_order2}
\title{Reorders layout observations based on specific statistics.}
\usage{
align_order2(
  stat,
  ...,
  reverse = FALSE,
  strict = TRUE,
  data = NULL,
  active = NULL
)
}
\arguments{
\item{stat}{A statistical function which accepts a data and returns the
statistic, which we'll call \code{\link[=order2]{order2()}} to extract the ordering information.}

\item{...}{<\link[rlang:dyn-dots]{dyn-dots}> Additional arguments passed to
function provided in \code{stat} argument.}

\item{reverse}{A boolean value. Should the sort order be in reverse?}

\item{strict}{A boolean value indicates whether the order should be strict.
If previous groups has been established, and strict is \code{FALSE}, this will
reorder the observations in each group.}

\item{data}{A \code{matrix}, \verb{data frame}, or atomic vector used as the input for
the \code{stat} function. Alternatively, you can specify a \code{function} (including
purrr-like lambda syntax) that will be applied to the layout matrix,
transforming it as necessary for statistic calculations. By default, it will
inherit from the layout matrix.}

\item{active}{A \code{\link[=active]{active()}} object that defines the context settings when
added to a layout.}
}
\description{
Reorders layout observations based on specific statistics.
}
\details{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}}

The \code{align_order2()} function differs from \code{align_order()} in that the
\code{weights} argument in \code{align_order()} must return atomic weights for each
observation. In contrast, the \code{stat} argument in \code{align_order2()} can
return more complex structures, such as \link[stats:hclust]{hclust} or
\link[stats:dendrogram]{dendrogram}, among others.

Typically, you can achieve the functionality of \code{align_order2()} using
\code{align_order()} by manually extracting the ordering information from
the statistic.
}
\section{Discrete Axis Alignment}{

It is important to note that we consider rows as observations, meaning
\code{vec_size(data)}/\code{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).
}

\examples{
ggheatmap(matrix(rnorm(81), nrow = 9)) +
    anno_left() +
    align_order2(hclust2)
}
\seealso{
\code{\link[=order2]{order2()}}
}
