% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ringplot.R
\name{RingPlotAtomic}
\alias{RingPlotAtomic}
\title{Atomic ring plot (internal)}
\usage{
RingPlotAtomic(
  data,
  x = NULL,
  y = NULL,
  group_by = NULL,
  group_by_sep = "_",
  group_name = NULL,
  label = NULL,
  clockwise = TRUE,
  keep_na = FALSE,
  keep_empty = FALSE,
  facet_by = NULL,
  facet_scales = "free_y",
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_byrow = TRUE,
  theme = "theme_this",
  theme_args = list(),
  palette = "Paired",
  palcolor = NULL,
  palreverse = FALSE,
  alpha = 1,
  aspect.ratio = 1,
  legend.position = "right",
  legend.direction = "vertical",
  title = NULL,
  subtitle = NULL,
  xlab = NULL,
  ylab = NULL,
  seed = 8525,
  ...
)
}
\arguments{
\item{data}{A data frame.}

\item{x}{A character string specifying the column to define the rings
(concentric layers) of the plot.  Each unique value becomes one ring.
When \code{NULL}, a single-ring (pie-chart-like) plot is produced.
Character or factor columns are expected.  Multiple columns are not
supported for \code{x} in ring plots.}

\item{y}{A character string specifying the numeric column for segment
sizing.  When \code{NULL} (default), the count of observations in each
(\code{x}, \code{group_by}, \code{facet_by}) combination is used.
Values are always normalised to proportions within each ring.}

\item{group_by}{A character vector of column names to divide each ring
into filled segments.  Each unique combination becomes one segment per
ring.  Multiple columns are concatenated with \code{group_by_sep}.
When \code{NULL}, a single unsegmented ring is drawn and the legend
is hidden.}

\item{group_by_sep}{A character string to join multiple \code{group_by}
columns.  Default \code{"_"}.  Ignored when \code{group_by} is a single
column.}

\item{group_name}{A character string used as the fill legend title.
When \code{NULL}, the \code{group_by} column name is used.}

\item{label}{A logical value controlling whether ring labels are shown.
Labels display the \code{x} values (ring names) at the inner edge of
each ring.  Default \code{NULL} auto-selects: \code{FALSE} for
single-ring plots, \code{TRUE} for multi-ring plots.}

\item{clockwise}{A logical value.  When \code{TRUE} (default), segments
within each ring are drawn clockwise (top-to-right).  When
\code{FALSE}, they are drawn counter-clockwise.  The legend also
reverses to match the drawing order.}

\item{keep_na}{A logical value or a character to replace the NA values in the data.
It can also take a named list to specify different behavior for different columns.
If TRUE or NA, NA values will be replaced with NA.
If FALSE, NA values will be removed from the data before plotting.
If a character string is provided, NA values will be replaced with the provided string.
If a named vector/list is provided, the names should be the column names to apply the behavior to,
and the values should be one of TRUE, FALSE, or a character string.
Without a named vector/list, the behavior applies to categorical/character columns used on the plot,
for example, the \code{x}, \code{group_by}, \code{fill_by}, etc.}

\item{keep_empty}{One of FALSE, TRUE and "level". It can also take a named list to specify
different behavior for different columns. Without a named list, the behavior applies to the
categorical/character columns used on the plot, for example, the \code{x}, \code{group_by}, \code{fill_by}, etc.
\itemize{
\item{\code{FALSE} (default): Drop empty factor levels from the data before plotting.}
\item{\code{TRUE}: Keep empty factor levels and show them as a separate category in the plot.}
\item{\code{"level"}: Keep empty factor levels, but do not show them in the plot.
But they will be assigned colors from the palette to maintain consistency across multiple plots.
Alias: \code{levels}}
}}

\item{facet_by}{A character string specifying the column name of the data frame to facet the plot.
Otherwise, the data will be split by \code{split_by} and generate multiple plots
and combine them into one using \code{patchwork::wrap_plots}}

\item{facet_scales}{Whether to scale the axes of facets. Default is "fixed"
Other options are "free", "free_x", "free_y". See \code{ggplot2::facet_wrap}}

\item{facet_ncol}{A numeric value specifying the number of columns in the facet.
When facet_by is a single column and facet_wrap is used.}

\item{facet_nrow}{A numeric value specifying the number of rows in the facet.
When facet_by is a single column and facet_wrap is used.}

\item{facet_byrow}{A logical value indicating whether to fill the plots by row. Default is TRUE.}

\item{theme}{A character string or a theme class (i.e. ggplot2::theme_classic) specifying the theme to use.
Default is "theme_this".}

\item{theme_args}{A list of arguments to pass to the theme function.}

\item{palette}{A character string specifying the palette to use.
A named list or vector can be used to specify the palettes for different \code{split_by} values.}

\item{palcolor}{A character string specifying the color to use in the palette.
A named list can be used to specify the colors for different \code{split_by} values.
If some values are missing, the values from the palette will be used (palcolor will be NULL for those values).}

\item{palreverse}{A logical value indicating whether to reverse the palette. Default is FALSE.}

\item{alpha}{A numeric value specifying the transparency of the plot.}

\item{aspect.ratio}{A numeric value specifying the aspect ratio of the plot.}

\item{legend.position}{A character string specifying the position of the legend.
if \code{waiver()}, for single groups, the legend will be "none", otherwise "right".}

\item{legend.direction}{A character string specifying the direction of the legend.}

\item{title}{A character string specifying the title of the plot.
A function can be used to generate the title based on the default title.
This is useful when split_by is used and the title needs to be dynamic.}

\item{subtitle}{A character string specifying the subtitle of the plot.}

\item{xlab}{A character string specifying the x-axis label.}

\item{ylab}{A character string specifying the y-axis label.}

\item{seed}{The random seed to use. Default is 8525.}

\item{...}{Additional arguments.}
}
\value{
A \code{ggplot} object with \code{height} and \code{width}
attributes (in inches) attached.
}
\description{
Core implementation for drawing a single ring (multi-layer donut) plot.
This is the workhorse behind the exported \code{\link{RingPlot}} function —
it takes a \strong{single} data frame (no \code{split_by} support) and returns a
\code{ggplot} object.  Each level of \code{x} becomes a concentric ring,
and within each ring the \code{group_by} variable divides the ring into
filled segments drawn via \code{geom_col()} with \code{coord_polar("y")}.

When \code{y = NULL}, the count of observations per combination is used.
y-values are always normalised to proportions (0–1) within each
(\code{x}, \code{facet_by}) group so that each complete ring sums to 1.
}
\section{Architecture}{

\enumerate{
\item \strong{Column resolution} — \code{x}, \code{group_by}, \code{y},
and \code{facet_by} are validated and transformed via
\code{\link{check_columns}}.  If \code{x} is \code{NULL}, a dummy
\code{.x} column (value \code{1}) is created, producing a single-ring
(pie-chart-like) plot.  If \code{group_by} is \code{NULL}, a dummy
\code{.group_by} factor is created and the legend is suppressed.
Multi-column \code{group_by} inputs are concatenated with
\code{group_by_sep}.
\item \strong{NA / empty-level handling} — \code{\link{process_keep_na_empty}()}
applies \code{keep_na} and \code{keep_empty} policies.  Per-column
\code{keep_empty} settings are extracted for \code{x},
\code{group_by}, and \code{facet_by} independently.  The facet
columns must have identical \code{keep_empty} values.
\item \strong{Count aggregation} — when \code{y = NULL}, the count of
observations in each unique (\code{x}, \code{group_by},
\code{facet_by}) combination is computed as a new \code{.y} column.
Factor levels are preserved after aggregation.
\item \strong{Proportion scaling} — y-values are divided by the sum within
each (\code{x}, \code{facet_by}) group, normalising each ring to
sum to 1.0.  This is essential for polar coordinates where each ring
represents a full 360 degrees.
\item \strong{Ring resolution} — The levels of \code{x} are reversed so
the outermost ring appears first in the data (rings are drawn
outward from the origin).  \code{NA} levels are appended.
\item \strong{Label logic} — When \code{label = NULL}, labels are
automatically suppressed for single-ring plots and shown for
multi-ring plots.  Labels are placed at the inner edge of each ring
via \code{geom_label()}.
\item \strong{Clockwise ordering} — When \code{clockwise = TRUE} (default),
the \code{group_by} levels are reversed so segments appear clockwise
from the top.  The legend guide also reverses its order.
\item \strong{Colour mapping} — \code{\link{palette_this}()} assigns
colours to all \code{group_by} levels, including \code{NA}
(defaulting to \code{"grey80"}).
\item \strong{Plot assembly} — The \code{ggplot} object is built with
\code{geom_col()} (ring segments), \code{coord_polar("y")} (polar
transform), \code{scale_x_discrete()} (with a leading space level
as the donut hole), and \code{scale_fill_manual()} with per-group
colours.  All axes, ticks, grid lines, and panel borders are removed
for a clean appearance.  The fill scale \code{drop} argument is
controlled by \code{keep_empty_group}.
\item \strong{Dimension calculation} — \code{\link{calculate_plot_dimensions}()}
computes plot height and width from \code{aspect.ratio} and legend
metrics.  The resulting \code{height} / \code{width} attributes are
stored on the \code{ggplot} object.
\item \strong{Faceting} — \code{\link{facet_plot}()} wraps the plot with
\code{facet_wrap} / \code{facet_grid} if \code{facet_by} is
provided, respecting the \code{keep_empty} setting for facet
variables.
}
}

\keyword{internal}
