% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/barplot.R
\name{BarPlotAtomic}
\alias{BarPlotAtomic}
\title{Atomic bar plot (internal)}
\usage{
BarPlotAtomic(
  data,
  x,
  x_sep = "_",
  y = NULL,
  scale_y = FALSE,
  flip = FALSE,
  group_by = NULL,
  group_by_sep = "_",
  group_name = NULL,
  fill_by = TRUE,
  fill_name = NULL,
  label_nudge = 0.02,
  label = NULL,
  label_fg = "black",
  label_size = 4,
  label_bg = "white",
  label_bg_r = 0.1,
  add_bg = FALSE,
  bg_palette = "stripe",
  bg_palcolor = NULL,
  bg_alpha = 0.2,
  theme = "theme_this",
  theme_args = list(),
  palette = NULL,
  palcolor = NULL,
  palreverse = FALSE,
  alpha = 1,
  lower_quantile = 0,
  upper_quantile = 0.99,
  lower_cutoff = NULL,
  upper_cutoff = NULL,
  x_text_angle = 0,
  aspect.ratio = 1,
  add_line = NULL,
  line_color = "red2",
  line_width = 0.6,
  line_type = 2,
  line_name = NULL,
  add_trend = FALSE,
  trend_color = "black",
  trend_linewidth = 1,
  trend_ptsize = 2,
  position = "auto",
  position_dodge_preserve = "total",
  y_min = NULL,
  y_max = NULL,
  legend.position = "right",
  legend.direction = "vertical",
  title = NULL,
  subtitle = NULL,
  xlab = NULL,
  ylab = NULL,
  keep_na = FALSE,
  keep_empty = FALSE,
  expand = waiver(),
  width = waiver(),
  facet_by = NULL,
  facet_scales = "fixed",
  facet_nrow = NULL,
  facet_ncol = NULL,
  facet_byrow = TRUE,
  facet_args = list(),
  ...
)
}
\arguments{
\item{data}{A data frame.}

\item{x}{A character string specifying the column name of the data frame to plot for the x-axis.}

\item{x_sep}{A character string to join multiple \code{x} columns.
Default \code{"_"}.}

\item{y}{A character string specifying the column name of the data frame to plot for the y-axis.}

\item{scale_y}{A logical value.  When \code{TRUE}, y-values are scaled to
proportions within each x position so that each position's total is 100\\%.
Only applicable when \code{position = "stack"}.}

\item{flip}{Logical; if \code{TRUE}, swap the x and y axes.}

\item{group_by}{Columns to group the data for plotting
For those plotting functions that do not support multiple groups,
They will be concatenated into one column, using \code{group_by_sep} as the separator}

\item{group_by_sep}{The separator for multiple group_by columns. See \code{group_by}}

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

\item{fill_by}{A variable used to fill the bars.  Both categorical and
numeric columns are accepted:
\itemize{
\item \code{TRUE} (default) — fill by the x-axis values.
\item \code{FALSE} — solid fill (first palette colour).
\item A column name (character/factor) — discrete colour scale.
\item A column name (numeric) — continuous gradient with quantile
/ cutoff controls.
}
Ignored when \code{group_by} is provided (fill is determined by
\code{group_by}).}

\item{fill_name}{A character string for the fill legend title.  Only
applies when \code{group_by = NULL} and the fill is from \code{fill_by}.}

\item{label_nudge}{A numeric value controlling the distance between labels
and the bar top, expressed as a fraction of the data range.}

\item{label}{A column name (or \code{TRUE}) for text labels on bars.
When \code{TRUE}, the y-axis values are labelled.  When a column name,
the values in that column are used.}

\item{label_fg}{A character string specifying the label text colour.}

\item{label_size}{A numeric value specifying the label text size.}

\item{label_bg}{A character string specifying the label background colour.}

\item{label_bg_r}{A numeric value specifying the label background corner
radius.}

\item{add_bg}{Logical; add alternating background stripes behind the bars.}

\item{bg_palette}{Palette for the background stripes.}

\item{bg_palcolor}{Custom colours for the background stripes.}

\item{bg_alpha}{Alpha transparency for the background stripes.}

\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{lower_quantile, upper_quantile}{Lower and upper quantiles for the continuous color/fill scale.
The actual cutoffs are determined by these quantiles when \code{lower_cutoff} and
\code{upper_cutoff} are \code{NULL}. Defaults: \code{lower_quantile = 0}, \code{upper_quantile = 0.99}.}

\item{lower_cutoff, upper_cutoff}{Explicit lower and upper cutoffs for the continuous color/fill scale.
When \code{NULL} (the default), the cutoffs are determined by \code{lower_quantile} and
\code{upper_quantile} via \code{\link[stats]{quantile}}. Values outside the
\code{[lower_cutoff, upper_cutoff]} range are clamped (winsorized) to the nearest cutoff value.}

\item{x_text_angle}{A numeric value specifying the angle of the x-axis text.}

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

\item{add_line}{A numeric y-intercept for a horizontal reference line.}

\item{line_color}{Colour of the reference line.}

\item{line_width}{Width of the reference line.}

\item{line_type}{Linetype of the reference line (e.g., 1 = solid, 2 = dashed).}

\item{line_name}{Legend name for the reference line.}

\item{add_trend}{Logical; add a trend line and points connecting the bar tops.}

\item{trend_color}{Colour of the trend line.}

\item{trend_linewidth}{Width of the trend line.}

\item{trend_ptsize}{Size of the trend line points.}

\item{position}{A character string specifying the bar layout:
\code{"auto"} (default: dodge when \eqn{\le}5 groups, stack otherwise),
\code{"dodge"} (side-by-side), or \code{"stack"} (stacked on top of
each other).}

\item{position_dodge_preserve}{A character string passed to
\code{\link[ggplot2]{position_dodge2}()}: \code{"total"} preserves the
overall bar group width; \code{"single"} preserves individual bar widths.}

\item{y_min, y_max}{Numeric limits for the y-axis (or x-axis when flipped).}

\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{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{expand}{The values to expand the x and y axes. It is like CSS padding.
When a single value is provided, it is used for both axes on both sides.
When two values are provided, the first value is used for the top/bottom side and the second value is used for the left/right side.
When three values are provided, the first value is used for the top side, the second value is used for the left/right side, and the third value is used for the bottom side.
When four values are provided, the values are used for the top, right, bottom, and left sides, respectively.
You can also use a named vector to specify the values for each side.
When the axis is discrete, the values will be applied as 'add' to the 'expansion' function.
When the axis is continuous, the values will be applied as 'mult' to the 'expansion' function.
See also \url{https://ggplot2.tidyverse.org/reference/expansion.html}}

\item{width}{A numeric value specifying the bar width (0–1).}

\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_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_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_byrow}{A logical value indicating whether to fill the plots by row. Default is TRUE.}

\item{facet_args}{A list of additional arguments passed to the faceting
function (e.g., \code{scales}, \code{labeller}).}

\item{...}{Additional arguments.}
}
\value{
A \code{ggplot} object, possibly faceted, with \code{height}
and \code{width} attributes (in inches) attached.
}
\description{
Dispatcher that routes to \code{\link{BarPlotSingle}} (when
\code{group_by = NULL}) or \code{\link{BarPlotGrouped}} (when
\code{group_by} is provided).  This is the core implementation layer —
it takes a \strong{single} data frame (no \code{split_by} support) and returns
a \code{ggplot} object with faceting applied.
}
\section{Dispatch logic}{

\itemize{
\item \strong{Without \code{group_by}} — delegates to
\code{BarPlotSingle}.  \code{fill_by} controls bar colouring:
\code{TRUE} (default) fills by x-axis values, \code{FALSE} uses a
single colour, a character column produces discrete colours, and
a numeric column produces a continuous gradient.
\item \strong{With \code{group_by}} — delegates to
\code{BarPlotGrouped}.  \code{fill_by} must match \code{group_by}
or be left as default; an explicit mismatch raises a stop error.
\code{position} controls dodge vs. stack layout with automatic
selection based on group count (\eqn{\le}5 → dodge, >5 → stack).
}

After the delegate returns, \code{\link{facet_plot}()} wraps the result
with \code{facet_wrap} / \code{facet_grid} if \code{facet_by} is provided.
}

\keyword{internal}
