% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/stat_slabinterval.R
\name{stat_slabinterval}
\alias{stat_slabinterval}
\title{Slab + interval plots for sample data and analytical distributions (ggplot stat)}
\usage{
stat_slabinterval(
  mapping = NULL,
  data = NULL,
  geom = "slabinterval",
  position = "identity",
  ...,
  p_limits = c(NA, NA),
  density = "bounded",
  adjust = waiver(),
  trim = waiver(),
  breaks = waiver(),
  align = waiver(),
  outline_bars = waiver(),
  expand = FALSE,
  point_interval = "median_qi",
  limits = NULL,
  n = waiver(),
  .width = c(0.66, 0.95),
  orientation = NA,
  na.rm = FALSE,
  show.legend = c(size = FALSE),
  inherit.aes = TRUE
)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link[ggplot2:aes]{aes()}}. If specified and
\code{inherit.aes = TRUE} (the default), it is combined with the default mapping
at the top level of the plot. You must supply \code{mapping} if there is no plot
mapping.}

\item{data}{The data to be displayed in this layer. There are three
options:

If \code{NULL}, the default, the data is inherited from the plot
data as specified in the call to \code{\link[ggplot2:ggplot]{ggplot()}}.

A \code{data.frame}, or other object, will override the plot
data. All objects will be fortified to produce a data frame. See
\code{\link[ggplot2:fortify]{fortify()}} for which variables will be created.

A \code{function} will be called with a single argument,
the plot data. The return value must be a \code{data.frame}, and
will be used as the layer data. A \code{function} can be created
from a \code{formula} (e.g. \code{~ head(.x, 10)}).}

\item{geom}{<\link[ggplot2:ggplot2-ggproto]{Geom} | \link[=character]{string}> Use to override the
default connection between \code{\link[=stat_slabinterval]{stat_slabinterval()}} and \code{\link[=geom_slabinterval]{geom_slabinterval()}}.}

\item{position}{<\link[ggplot2:ggplot2-ggproto]{Position} | \link[=character]{string}> Position adjustment,
either as a string, or the result of a call to a position adjustment function.
Setting this equal to \code{"dodge"} (\code{\link[ggplot2:position_dodge]{position_dodge()}}) or
\code{"dodgejust"} (\code{\link[=position_dodgejust]{position_dodgejust()}}) can be useful if you have overlapping geometries.}

\item{...}{Other arguments passed to \code{\link[ggplot2:layer]{layer()}}. These are often aesthetics, used to set an aesthetic
to a fixed value, like \code{colour = "red"} or \code{linewidth = 3} (see \strong{Aesthetics}, below). They may also be
parameters to the paired geom/stat. When paired with the default geom, \code{\link[=geom_slabinterval]{geom_slabinterval()}},
these include:
\describe{
\item{\code{subscale}}{<\link{function} | \link[=character]{string}> Sub-scale used to scale values of the
\code{thickness} aesthetic within the groups determined by \code{normalize}. One of:
\itemize{
\item A function that takes an \code{x} argument giving a numeric vector
of values to be scaled and then returns a \link{thickness} vector representing
the scaled values, such as \code{\link[=subscale_thickness]{subscale_thickness()}} or \code{\link[=subscale_identity]{subscale_identity()}}.
\item A string giving the name of such a function when prefixed
with \code{"subscale_"}; e.g. \code{"thickness"} or \code{"identity"}. The value
\code{"thickness"} using the default subscale, which can be modified by
setting \code{\link{subscale_thickness}}; see the documentation for that
function.
}
For a comprehensive discussion and examples of slab scaling and normalization, see the
\href{https://mjskay.github.io/ggdist/articles/thickness.html}{\code{thickness} scale article}.}
\item{\code{normalize}}{<\link[=character]{string}> Groups within which to scale values of the \code{thickness} aesthetic. One of:
\itemize{
\item \code{"all"}: normalize so that the maximum height across all data is \code{1}.
\item \code{"panels"}: normalize within panels so that the maximum height in each panel is \code{1}.
\item \code{"xy"}: normalize within the x/y axis opposite the \code{orientation} of this geom so
that the maximum height at each value of the opposite axis is \code{1}.
\item \code{"groups"}: normalize within values of the opposite axis and within each
group so that the maximum height in each group is \code{1}.
\item \code{"none"}: values are taken as is with no normalization (this should probably
only be used with functions whose values are in [0,1], such as CDFs).
}
For a comprehensive discussion and examples of slab scaling and normalization, see the
\href{https://mjskay.github.io/ggdist/articles/thickness.html}{\code{thickness} scale article}.}
\item{\code{fill_type}}{<\link[=character]{string}> What type of fill to use when the fill color or alpha varies within a slab.
One of:
\itemize{
\item \code{"segments"}: breaks up the slab geometry into segments for each unique combination of fill color and
alpha value. This approach is supported by all graphics devices and works well for sharp cutoff values,
but can give ugly results if a large number of unique fill colors are being used (as in gradients,
like in \code{\link[=stat_gradientinterval]{stat_gradientinterval()}}).
\item \code{"gradient"}: a \code{grid::linearGradient()} is used to create a smooth gradient fill. This works well for
large numbers of unique fill colors, but requires R >= 4.1 and is not yet supported on all graphics devices.
As of this writing, the \code{png()} graphics device with \code{type = "cairo"}, the \code{svg()} device, the \code{pdf()}
device, and the \code{ragg::agg_png()} devices are known to support this option. On R < 4.1, this option
will fall back to \code{fill_type = "segments"} with a message.
\item \code{"auto"}: attempts to use \code{fill_type = "gradient"} if support for it can be auto-detected. On R >= 4.2,
support for gradients can be auto-detected on some graphics devices; if support is not detected, this
option will fall back to \code{fill_type = "segments"} (in case of a false negative, \code{fill_type = "gradient"}
can be set explicitly). On R < 4.2, support for gradients cannot be auto-detected, so this will always
fall back to \code{fill_type = "segments"}, in which case you can set \code{fill_type = "gradient"} explicitly
if you are using a graphics device that support gradients.
}}
\item{\code{interval_size_domain}}{<length-2 \link{numeric}> Minimum and maximum of the values of the \code{size} and \code{linewidth} aesthetics
that will be translated into actual sizes for intervals drawn according to \code{interval_size_range} (see the
documentation for that argument.)}
\item{\code{interval_size_range}}{<length-2 \link{numeric}> This geom scales the raw size aesthetic values when drawing interval
and point sizes, as they tend to be too thick when using the default settings of \code{\link[ggplot2:scale_size]{scale_size_continuous()}},
which give sizes with a range of \code{c(1, 6)}. The \code{interval_size_domain} value indicates the
input domain of raw size values (typically this should be equal to the value of the \code{range}
argument of the \code{\link[ggplot2:scale_size]{scale_size_continuous()}} function), and
\code{interval_size_range} indicates the desired output range of the size values (the min and max
of the actual sizes used to draw intervals). Most of the time it is not recommended to change
the value of this argument, as it may result in strange scaling of legends; this argument is
a holdover from earlier versions that did not have size aesthetics targeting the point and
interval separately. If you want to adjust the size of the interval or points separately,
you can also use the \code{linewidth} or \code{point_size} aesthetics; see \link{sub-geometry-scales}.}
\item{\code{fatten_point}}{<scalar \link{numeric}> A multiplicative factor used to adjust the size of the point relative to the
size of the thickest interval line. If you wish to specify point sizes directly, you can also use
the \code{point_size} aesthetic and \code{\link[=scale_point_size_continuous]{scale_point_size_continuous()}} or \code{\link[=scale_point_size_discrete]{scale_point_size_discrete()}};
sizes specified with that aesthetic will not be adjusted using \code{fatten_point}.}
\item{\code{arrow}}{<\link{arrow} | \link{NULL}> Type of arrow heads to use on the interval, or \code{NULL} for no arrows.}
\item{\code{subguide}}{<\link{function} | \link[=character]{string}> Sub-guide used to annotate the \code{thickness} scale. One of:
\itemize{
\item A function that takes a \code{scale} argument giving a \link[ggplot2:ggplot2-ggproto]{ggplot2::Scale}
object and an \code{orientation} argument giving the orientation of the
geometry and then returns a \link[grid:grid.grob]{grid::grob} that will draw the axis
annotation, such as \code{\link[=subguide_axis]{subguide_axis()}} (to draw a traditional axis) or
\code{\link[=subguide_none]{subguide_none()}} (to draw no annotation). See \code{\link[=subguide_axis]{subguide_axis()}}
for a list of possibilities and examples.
\item A string giving the name of such a function when prefixed
with \code{"subguide_"}; e.g. \code{"axis"} or \code{"none"}. The values \code{"slab"},
\code{"dots"}, and \code{"spike"} use the default subguide for their geom
families (no subguide), which can be modified by setting
\code{\link{subguide_slab}}, \code{\link{subguide_dots}}, or \code{\link{subguide_spike}};
see the documentation for those functions.
}}
}}

\item{p_limits}{<length-2 \link{numeric}> Probability limits. Used to determine the lower and upper
limits of \emph{analytical} distributions (distributions from \emph{samples} ignore this parameter and determine
their limits based on the limits of the sample and the value of the \code{trim} parameter).
E.g., if this is \code{c(.001, .999)}, then a slab is drawn
for the distribution from the quantile at \code{p = .001} to the quantile at \code{p = .999}. If the lower
(respectively upper) limit is \code{NA}, then the lower (upper) limit will be the minimum (maximum) of the
distribution's support if it is finite, and \code{0.001} (\code{0.999}) if it is not finite. E.g., if
\code{p_limits} is \code{c(NA, NA)}, on a gamma distribution the effective value of \code{p_limits} would be
\code{c(0, .999)} since the gamma distribution is defined on \verb{(0, Inf)}; whereas on a normal distribution
it would be equivalent to \code{c(.001, .999)} since the normal distribution is defined on \verb{(-Inf, Inf)}.}

\item{density}{<\link{function} | \link[=character]{string}> Density estimator for sample data. One of:
\itemize{
\item A function which takes a numeric vector and returns a list with elements
\code{x} (giving grid points for the density estimator) and \code{y} (the
corresponding densities). \pkg{ggdist} provides a family of functions
following this format, including \code{\link[=density_unbounded]{density_unbounded()}} and
\code{\link[=density_bounded]{density_bounded()}}. This format is also compatible with \code{\link[stats:density]{stats::density()}}.
\item A string giving the suffix of a function name that starts with \code{"density_"};
e.g. \code{"bounded"} for \verb{[density_bounded()]}, \code{"unbounded"} for \verb{[density_unbounded()]},
or \code{"histogram"} for \code{\link[=density_histogram]{density_histogram()}}.
Defaults to \code{"bounded"}, i.e. \code{\link[=density_bounded]{density_bounded()}}, which estimates the bounds from
the data and then uses a bounded density estimator based on the reflection method.
}}

\item{adjust}{<scalar \link{numeric} | \link{waiver}> Passed to \code{density} (e.g. \code{\link[=density_bounded]{density_bounded()}}): Value to multiply the bandwidth of the density estimator by. Default \code{\link[=waiver]{waiver()}} defers to the default of the density estimator, which is usually \code{1}.}

\item{trim}{<scalar \link{logical} | \link{waiver}> Passed to \code{density} (e.g. \code{\link[=density_bounded]{density_bounded()}}): Should the density estimate be trimmed to the range of the data? Default \code{\link[=waiver]{waiver()}} defers to the default of the density estimator, which is usually \code{TRUE}.}

\item{breaks}{<\link{numeric} | \link{function} | \link[=character]{string} | \link{waiver}> Passed to \code{density} (e.g. \code{\link[=density_histogram]{density_histogram()}}): Determines the breakpoints defining bins. Default \code{\link[=waiver]{waiver()}} defers to the default of the density estimator, which is usually \code{"Scott"}. Similar to (but not exactly the same as) the \code{breaks}
argument to \code{\link[graphics:hist]{graphics::hist()}}. One of:
\itemize{
\item A scalar (length-1) numeric giving the number of bins
\item A vector numeric giving the breakpoints between histogram bins
\item A function taking \code{x} and \code{weights} and returning either the
number of bins or a vector of breakpoints
\item A string giving the suffix of a function that starts with
\code{"breaks_"}. \pkg{ggdist} provides weighted implementations of the
\code{"Sturges"}, \code{"Scott"}, and \code{"FD"} break-finding algorithms from
\code{\link[graphics:hist]{graphics::hist()}}, as well as \code{\link[=breaks_fixed]{breaks_fixed()}} for manually setting
the bin width. See \link{breaks}.
}
For example, \code{breaks = "Sturges"} will use the \code{\link[=breaks_Sturges]{breaks_Sturges()}} algorithm,
\code{breaks = 9} will create 9 bins, and \code{breaks = breaks_fixed(width = 1)} will
set the bin width to \code{1}.}

\item{align}{<scalar \link{numeric} | \link{function} | \link[=character]{string} | \link{waiver}> Passed to \code{density} (e.g. \code{\link[=density_histogram]{density_histogram()}}): Determines how to align the breakpoints defining bins. Default \code{\link[=waiver]{waiver()}} defers to the default of the density estimator, which is usually \code{"none"} (performs no alignment). One of:
\itemize{
\item A scalar (length-1) numeric giving an offset that is subtracted
from the breaks. The offset must be between \code{0} and the bin width.
\item A function taking a sorted vector of \code{breaks} (bin edges) and
returning an offset to subtract from the breaks.
\item A string giving the suffix of a function that starts with
\code{"align_"} used to determine the alignment, such as \code{\link[=align_none]{align_none()}},
\code{\link[=align_boundary]{align_boundary()}}, or \code{\link[=align_center]{align_center()}}.
}
For example, \code{align = "none"} will provide no alignment,
\code{align = align_center(at = 0)} will center a bin on \code{0}, and
\code{align = align_boundary(at = 0)} will align a bin edge on \code{0}.}

\item{outline_bars}{<scalar \link{logical} | \link{waiver}> Passed to \code{density} (e.g. \code{\link[=density_histogram]{density_histogram()}}) and also
used for discrete analytical distributions (whose slabs are drawn as histograms). Determines
if outlines in between the bars are drawn. If \code{\link[=waiver]{waiver()}} or \code{FALSE}
(the default), the outline is drawn only along the tops of the bars. If \code{TRUE}, outlines in between
bars are also drawn (though you may have to set the \code{slab_color} or \code{color} aesthetic to
see the outlines).}

\item{expand}{<\link{logical}> For sample data, should the slab be expanded to the limits of the scale? Default \code{FALSE}.
Can be a length-two logical vector to control expansion to the lower and upper limit respectively.}

\item{point_interval}{<\link{function} | \link[=character]{string}> A function from the \code{\link[=point_interval]{point_interval()}} family
(e.g., \code{median_qi}, \code{mean_qi}, \code{mode_hdi}, etc), or a string giving the name of a function from that family
(e.g., \code{"median_qi"}, \code{"mean_qi"}, \code{"mode_hdi"}, etc; if a string, the caller's environment is searched
for the function, followed by the \pkg{ggdist} environment). This function determines the point summary
(typically mean, median, or mode) and interval type (quantile interval, \code{qi};
highest-density interval, \code{hdi}; or highest-density continuous interval, \code{hdci}). Output will
be converted to the appropriate \code{x}- or \code{y}-based aesthetics depending on the value of \code{orientation}.
See the \code{\link[=point_interval]{point_interval()}} family of functions for more information.}

\item{limits}{<length-2 \link{numeric}> Manually-specified limits for the slab, as a vector of length two. These limits are combined with those
computed based on \code{p_limits} as well as the limits defined by the scales of the plot to determine the
limits used to draw the slab functions: these limits specify the maximal limits; i.e., if specified, the limits
will not be wider than these (but may be narrower). Use \code{NA} to leave a limit alone; e.g.
\code{limits = c(0, NA)} will ensure that the lower limit does not go below 0, but let the upper limit
be determined by either \code{p_limits} or the scale settings.}

\item{n}{<scalar \link{numeric}> Number of points at which to evaluate the function that defines the slab. Also
passed to \code{density} (e.g. \code{\link[=density_bounded]{density_bounded()}}). Default \code{waiver()} uses the value \code{501}
for analytical distributions and defers to the default of the density estimator for
sample-based distributions, which is also usually \code{501}.}

\item{.width}{<\link{numeric}> The \code{.width} argument passed to \code{point_interval}: a vector of probabilities
to use that determine the widths of the resulting intervals. If multiple probabilities are provided,
multiple intervals per group are generated, each with a different probability interval (and
value of the corresponding \code{.width} and \code{level} generated variables).}

\item{orientation}{<\link[=character]{string}> Whether this geom is drawn horizontally or vertically. One of:
\itemize{
\item \code{NA} (default): automatically detect the orientation based on how the aesthetics
are assigned. Automatic detection works most of the time.
\item \code{"horizontal"} (or \code{"y"}): draw horizontally, using the \code{y} aesthetic to identify different
groups. For each group, uses the \code{x}, \code{xmin}, \code{xmax}, and \code{thickness} aesthetics to
draw points, intervals, and slabs.
\item \code{"vertical"} (or \code{"x"}): draw vertically, using the \code{x} aesthetic to identify different
groups. For each group, uses the \code{y}, \code{ymin}, \code{ymax}, and \code{thickness} aesthetics to
draw points, intervals, and slabs.
}
For compatibility with the base ggplot naming scheme for \code{orientation}, \code{"x"} can be used as an alias
for \code{"vertical"} and \code{"y"} as an alias for \code{"horizontal"} (\pkg{ggdist} had an \code{orientation} parameter
before base ggplot did, hence the discrepancy).}

\item{na.rm}{<scalar \link{logical}> If \code{FALSE}, the default, missing values are removed with a warning. If \code{TRUE},
missing values are silently removed.}

\item{show.legend}{<\link{logical}> Should this layer be included in the legends? Default is \code{c(size = FALSE)},
unlike most geoms, to match its common use cases. \code{FALSE} hides all legends, \code{TRUE} shows all legends,
and \code{NA} shows only those that are mapped (the default for most geoms). It can also be a named logical
vector to finely select the aesthetics to display.}

\item{inherit.aes}{If \code{FALSE}, overrides the default aesthetics,
rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link[ggplot2:borders]{borders()}}.}
}
\value{
A \link[ggplot2:ggplot2-ggproto]{ggplot2::Stat} representing a slab or combined slab+interval geometry which can
be added to a \code{\link[ggplot2:ggplot]{ggplot()}} object.
}
\description{
"Meta" stat for computing distribution functions (densities or CDFs) + intervals for use with
\code{\link[=geom_slabinterval]{geom_slabinterval()}}. Useful for creating eye plots, half-eye plots, CCDF bar plots,
gradient plots, histograms, and more. Sample data can be supplied to the \code{x} and \code{y}
aesthetics or analytical distributions (in a variety of formats) can be supplied to the
\code{xdist} and \code{ydist} aesthetics.
See \strong{Details}.
}
\details{
A highly configurable stat for generating a variety of plots that combine a "slab"
that describes a distribution plus a point summary and any number of intervals.
Several "shortcut" stats are provided
which combine multiple options to create useful geoms, particularly \emph{eye plots}
(a violin plot of density plus interval), \emph{half-eye plots} (a density plot plus interval),
\emph{CCDF bar plots} (a complementary CDF plus interval), and \emph{gradient plots}
(a density encoded in color alpha plus interval).

The shortcut stats include:
\itemize{
\item \code{\link[=stat_eye]{stat_eye()}}: Eye plots (violin + interval)
\item \code{\link[=stat_halfeye]{stat_halfeye()}}: Half-eye plots (density + interval)
\item \code{\link[=stat_ccdfinterval]{stat_ccdfinterval()}}: CCDF bar plots (CCDF + interval)
\item \code{\link[=stat_cdfinterval]{stat_cdfinterval()}}: CDF bar plots (CDF + interval)
\item \code{\link[=stat_gradientinterval]{stat_gradientinterval()}}: Density gradient + interval plots
\item \code{\link[=stat_slab]{stat_slab()}}: Density plots
\item \code{\link[=stat_histinterval]{stat_histinterval()}}: Histogram + interval plots
\item \code{\link[=stat_pointinterval]{stat_pointinterval()}}: Point + interval plots
\item \code{\link[=stat_interval]{stat_interval()}}: Interval plots
}

\strong{To visualize sample data}, such as a data distribution, samples from a
bootstrap distribution, or a Bayesian posterior, you can supply samples to
the \code{x} or \code{y} aesthetic.

\strong{To visualize analytical distributions}, you can use the \code{xdist} or \code{ydist}
aesthetic. For historical reasons, you can also use \code{dist} to specify the distribution, though
this is not recommended as it does not work as well with orientation detection.
These aesthetics can be used as follows:
\itemize{
\item \code{xdist}, \code{ydist}, and \code{dist} can be any distribution object from the \href{https://pkg.mitchelloharawild.com/distributional/}{distributional}
package (\code{\link[distributional:dist_normal]{dist_normal()}}, \code{\link[distributional:dist_beta]{dist_beta()}}, etc)
or can be a \code{\link[posterior:rvar]{posterior::rvar()}} object. Since these functions are vectorized,
other columns can be passed directly to them in an \code{\link[ggplot2:aes]{aes()}} specification; e.g.
\code{aes(dist = dist_normal(mu, sigma))} will work if \code{mu} and \code{sigma} are columns in the
input data frame.
\item \code{dist} can be a character vector giving the distribution name. Then the  \code{arg1}, ... \code{arg9}
aesthetics (or \code{args} as a list column) specify distribution arguments. Distribution names
should correspond to R functions that have \code{"p"}, \code{"q"}, and \code{"d"} functions; e.g. \code{"norm"}
is a valid distribution name because R defines the \code{\link[=pnorm]{pnorm()}}, \code{\link[=qnorm]{qnorm()}}, and \code{\link[=dnorm]{dnorm()}}
functions for Normal distributions.

See the \code{\link[=parse_dist]{parse_dist()}} function for a useful way to generate \code{dist} and \code{args}
values from human-readable distribution specs (like \code{"normal(0,1)"}). Such specs are also
produced by other packages (like the \code{brms::get_prior} function in brms); thus,
\code{\link[=parse_dist]{parse_dist()}} combined with the stats described here can help you visualize the output
of those functions.
}
}
\section{Computed Variables}{

The following variables are computed by this stat and made available for
use in aesthetic specifications (\code{\link[ggplot2:aes]{aes()}}) using the \code{\link[ggplot2:aes_eval]{after_stat()}}
function or the \code{after_stat} argument of \code{\link[ggplot2:aes_eval]{stage()}}:
\itemize{
\item \code{x} or \code{y}: For slabs, the input values to the slab function.
For intervals, the point summary from the interval function. Whether it is \code{x} or \code{y} depends on \code{orientation}
\item \code{xmin} or \code{ymin}: For intervals, the lower end of the interval from the interval function.
\item \code{xmax} or \code{ymax}: For intervals, the upper end of the interval from the interval function.
\item \code{.width}: For intervals, the interval width as a numeric value in \verb{[0, 1]}.
For slabs, the width of the smallest interval containing that value of the slab.
\item \code{level}: For intervals, the interval width as an ordered factor.
For slabs, the level of the smallest interval containing that value of the slab.
\item \code{pdf}: For slabs, the probability density function (PDF).
If \code{options("ggdist.experimental.slab_data_in_intervals")} is \code{TRUE}:
For intervals, the PDF at the point summary; intervals also have \code{pdf_min} and \code{pdf_max}
for the PDF at the lower and upper ends of the interval.
\item \code{cdf}: For slabs, the cumulative distribution function.
If \code{options("ggdist.experimental.slab_data_in_intervals")} is \code{TRUE}:
For intervals, the CDF at the point summary; intervals also have \code{cdf_min} and \code{cdf_max}
for the CDF at the lower and upper ends of the interval.
\item \code{n}: For slabs, the number of data points summarized into that slab. If the slab was created from
an analytical distribution via the \code{xdist}, \code{ydist}, or \code{dist} aesthetic, \code{n} will be \code{Inf}.
\item \code{f}: (deprecated) For slabs, the output values from the slab function (such as the PDF, CDF, or CCDF),
determined by \code{slab_type}. Instead of using \code{slab_type} to change \code{f} and then mapping \code{f} onto an
aesthetic, it is now recommended to simply map the corresponding computed variable (e.g. \code{pdf}, \code{cdf}, or
\code{1 - cdf}) directly onto the desired aesthetic.
}
}

\section{Aesthetics}{

The slab+interval \code{stat}s and \code{geom}s have a wide variety of aesthetics that control
the appearance of their three sub-geometries: the \strong{slab}, the \strong{point}, and
the \strong{interval}.

These \code{stat}s support the following aesthetics:

\itemize{
\item{\code{x}: x position of the geometry (when orientation = \code{"vertical"}); or sample data to be summarized
(when \code{orientation = "horizontal"} with sample data).}
\item{\code{y}: y position of the geometry (when orientation = \code{"horizontal"}); or sample data to be summarized
(when \code{orientation = "vertical"} with sample data).}
\item{\code{weight}: When using samples (i.e. the \code{x} and \code{y} aesthetics, not \code{xdist} or \code{ydist}), optional
weights to be applied to each draw.}
\item{\code{xdist}: When using analytical distributions, distribution to map on the x axis: a \pkg{distributional}
object (e.g. \code{\link[distributional:dist_normal]{dist_normal()}}) or a \code{\link[posterior:rvar]{posterior::rvar()}} object.}
\item{\code{ydist}: When using analytical distributions, distribution to map on the y axis: a \pkg{distributional}
object (e.g. \code{\link[distributional:dist_normal]{dist_normal()}}) or a \code{\link[posterior:rvar]{posterior::rvar()}} object.}
\item{\code{dist}: When using analytical distributions, a name of a distribution (e.g. \code{"norm"}), a
\pkg{distributional} object (e.g. \code{\link[distributional:dist_normal]{dist_normal()}}), or a \code{\link[posterior:rvar]{posterior::rvar()}} object. See \strong{Details}.}
\item{\code{args}: Distribution arguments (\code{args} or \code{arg1}, ... \code{arg9}). See \strong{Details}.}
}

In addition, in their default configuration (paired with \code{\link[=geom_slabinterval]{geom_slabinterval()}})
the following aesthetics are supported by the underlying geom:

\strong{Slab-specific aesthetics}

\itemize{
\item{\code{thickness}: The thickness of the slab at each \code{x} value (if \code{orientation = "horizontal"}) or
\code{y} value (if \code{orientation = "vertical"}) of the slab.}
\item{\code{side}: Which side to place the slab on. \code{"topright"}, \code{"top"}, and \code{"right"} are synonyms
which cause the slab to be drawn on the top or the right depending on if \code{orientation} is \code{"horizontal"}
or \code{"vertical"}. \code{"bottomleft"}, \code{"bottom"}, and \code{"left"} are synonyms which cause the slab
to be drawn on the bottom or the left depending on if \code{orientation} is \code{"horizontal"} or
\code{"vertical"}. \code{"topleft"} causes the slab to be drawn on the top or the left, and \code{"bottomright"}
causes the slab to be drawn on the bottom or the right. \code{"both"} draws the slab mirrored on both
sides (as in a violin plot).}
\item{\code{scale}: What proportion of the region allocated to this geom to use to draw the slab. If \code{scale = 1},
slabs that use the maximum range will just touch each other. Default is \code{0.9} to leave some space
between adjacent slabs. For a comprehensive discussion and examples of slab scaling and normalization,
see the \href{https://mjskay.github.io/ggdist/articles/thickness.html}{\code{thickness} scale article}.}
\item{\code{justification}: Justification of the interval relative to the slab, where \code{0} indicates bottom/left
justification and \code{1} indicates top/right justification (depending on \code{orientation}). If \code{justification}
is \code{NULL} (the default), then it is set automatically based on the value of \code{side}: when \code{side} is
\code{"top"}/\code{"right"} \code{justification} is set to \code{0}, when \code{side} is \code{"bottom"}/\code{"left"}
\code{justification} is set to \code{1}, and when \code{side} is \code{"both"} \code{justification} is set to 0.5.}
\item{\code{datatype}: When using composite geoms directly without a \code{stat} (e.g. \code{\link[=geom_slabinterval]{geom_slabinterval()}}), \code{datatype} is used to
indicate which part of the geom a row in the data targets: rows with \code{datatype = "slab"} target the
slab portion of the geometry and rows with \code{datatype = "interval"} target the interval portion of
the geometry. This is set automatically when using ggdist \code{stat}s.}
}

\strong{Interval-specific aesthetics}

\itemize{
\item{\code{xmin}: Left end of the interval sub-geometry (if \code{orientation = "horizontal"}).}
\item{\code{xmax}: Right end of the interval sub-geometry (if \code{orientation = "horizontal"}).}
\item{\code{ymin}: Lower end of the interval sub-geometry (if \code{orientation = "vertical"}).}
\item{\code{ymax}: Upper end of the interval sub-geometry (if \code{orientation = "vertical"}).}
}

\strong{Point-specific aesthetics}

\itemize{
\item{\code{shape}: Shape type used to draw the \strong{point} sub-geometry.}
}

\strong{Color aesthetics}

\itemize{
\item{\code{colour}: (or \code{color}) The color of the \strong{interval} and \strong{point} sub-geometries.
Use the \code{slab_color}, \code{interval_color}, or \code{point_color} aesthetics (below) to
set sub-geometry colors separately.}
\item{\code{fill}: The fill color of the \strong{slab} and \strong{point} sub-geometries. Use the \code{slab_fill}
or \code{point_fill} aesthetics (below) to set sub-geometry colors separately.}
\item{\code{alpha}: The opacity of the \strong{slab}, \strong{interval}, and \strong{point} sub-geometries. Use the \code{slab_alpha},
\code{interval_alpha}, or \code{point_alpha} aesthetics (below) to set sub-geometry colors separately.}
\item{\code{colour_ramp}: (or \code{color_ramp}) A secondary scale that modifies the \code{color}
scale to "ramp" to another color. See \code{\link[=scale_colour_ramp]{scale_colour_ramp()}} for examples.}
\item{\code{fill_ramp}: A secondary scale that modifies the \code{fill}
scale to "ramp" to another color. See \code{\link[=scale_fill_ramp]{scale_fill_ramp()}} for examples.}
}

\strong{Line aesthetics}

\itemize{
\item{\code{linewidth}: Width of the line used to draw the \strong{interval} (except with \code{\link[=geom_slab]{geom_slab()}}: then
it is the width of the \strong{slab}). With composite geometries including an interval and slab,
use \code{slab_linewidth} to set the line width of the \strong{slab} (see below). For \strong{interval}, raw
\code{linewidth} values are transformed according to the \code{interval_size_domain} and \code{interval_size_range}
parameters of the \code{geom} (see above).}
\item{\code{size}: Determines the size of the \strong{point}. If \code{linewidth} is not provided, \code{size} will
also determines the width of the line used to draw the \strong{interval} (this allows line width and
point size to be modified together by setting only \code{size} and not \code{linewidth}). Raw
\code{size} values are transformed according to the \code{interval_size_domain}, \code{interval_size_range},
and \code{fatten_point} parameters of the \code{geom} (see above). Use the \code{point_size} aesthetic
(below) to set sub-geometry size directly without applying the effects of
\code{interval_size_domain}, \code{interval_size_range}, and \code{fatten_point}.}
\item{\code{stroke}: Width of the outline around the \strong{point} sub-geometry.}
\item{\code{linetype}: Type of line (e.g., \code{"solid"}, \code{"dashed"}, etc) used to draw the \strong{interval}
and the outline of the \strong{slab} (if it is visible). Use the \code{slab_linetype} or
\code{interval_linetype} aesthetics (below) to set sub-geometry line types separately.}
}

\strong{Slab-specific color and line override aesthetics}

\itemize{
\item{\code{slab_fill}: Override for \code{fill}: the fill color of the slab.}
\item{\code{slab_colour}: (or \code{slab_color}) Override for \code{colour}/\code{color}: the outline color of the slab.}
\item{\code{slab_alpha}: Override for \code{alpha}: the opacity of the slab.}
\item{\code{slab_linewidth}: Override for \code{linwidth}: the width of the outline of the slab.}
\item{\code{slab_linetype}: Override for \code{linetype}: the line type of the outline of the slab.}
}

\strong{Interval-specific color and line override aesthetics}

\itemize{
\item{\code{interval_colour}: (or \code{interval_color}) Override for \code{colour}/\code{color}: the color of the interval.}
\item{\code{interval_alpha}: Override for \code{alpha}: the opacity of the interval.}
\item{\code{interval_linetype}: Override for \code{linetype}: the line type of the interval.}
}

\strong{Point-specific color and line override aesthetics}

\itemize{
\item{\code{point_fill}: Override for \code{fill}: the fill color of the point.}
\item{\code{point_colour}: (or \code{point_color}) Override for \code{colour}/\code{color}: the outline color of the point.}
\item{\code{point_alpha}: Override for \code{alpha}: the opacity of the point.}
\item{\code{point_size}: Override for \code{size}: the size of the point.}
}

\strong{Deprecated aesthetics}

\itemize{
\item{\code{slab_size}: Use \code{slab_linewidth}.}
\item{\code{interval_size}: Use \code{interval_linewidth}.}
}

\strong{Other aesthetics} (these work as in standard \code{geom}s)

\itemize{
\item{\code{width}}
\item{\code{height}}
\item{\code{group}}
}

See examples of some of these aesthetics in action in \code{vignette("slabinterval")}.
Learn more about the sub-geom override aesthetics (like \code{interval_color}) in the
\link[ggdist]{scales} documentation. Learn more about basic ggplot aesthetics in
\code{vignette("ggplot2-specs")}.
}

\examples{

library(dplyr)
library(ggplot2)
library(distributional)

theme_set(theme_ggdist())


# EXAMPLES ON SAMPLE DATA
set.seed(1234)
df = data.frame(
  group = c("a", "b", "c", "c", "c"),
  value = rnorm(2500, mean = c(5, 7, 9, 9, 9), sd = c(1, 1.5, 1, 1, 1))
)

# here are vertical eyes:
df \%>\%
  ggplot(aes(x = group, y = value)) +
  stat_eye()

# note the sample size is not automatically incorporated into the
# area of the densities in case one wishes to plot densities against
# a reference (e.g. a prior distribution).
# But you may wish to account for sample size if using these geoms
# for something other than visualizing posteriors; in which case
# you can use after_stat(f*n):
df \%>\%
  ggplot(aes(x = group, y = value)) +
  stat_eye(aes(thickness = after_stat(pdf*n)))


# EXAMPLES ON ANALYTICAL DISTRIBUTIONS

dist_df = tribble(
  ~group, ~subgroup, ~mean, ~sd,
  "a",          "h",     5,   1,
  "b",          "h",     7,   1.5,
  "c",          "h",     8,   1,
  "c",          "i",     9,   1,
  "c",          "j",     7,   1
)

# Using functions from the distributional package (like dist_normal()) with the
# dist aesthetic can lead to more compact/expressive specifications

dist_df \%>\%
  ggplot(aes(x = group, ydist = dist_normal(mean, sd), fill = subgroup)) +
  stat_eye(position = "dodge")

# using the old character vector + args approach
dist_df \%>\%
  ggplot(aes(x = group, dist = "norm", arg1 = mean, arg2 = sd, fill = subgroup)) +
  stat_eye(position = "dodge")

# the stat_slabinterval family applies a Jacobian adjustment to densities
# when plotting on transformed scales in order to plot them correctly.
# It determines the Jacobian using symbolic differentiation if possible,
# using stats::D(). If symbolic differentation fails, it falls back
# to numericDeriv(), which is less reliable; therefore, it is
# advisable to use scale transformation functions that are defined in
# terms of basic math functions so that their derivatives can be
# determined analytically (most of the transformation functions in the
# scales package currently have this property).
# For example, here is a log-Normal distribution plotted on the log
# scale, where it will appear Normal:
data.frame(dist = "lnorm", logmean = log(10), logsd = 2*log(10)) \%>\%
  ggplot(aes(y = 1, dist = dist, arg1 = logmean, arg2 = logsd)) +
  stat_halfeye() +
  scale_x_log10(breaks = 10^seq(-5,7, by = 2))

# see vignette("slabinterval") for many more examples.

}
\seealso{
See \code{\link[=geom_slabinterval]{geom_slabinterval()}} for more information on the geom these stats
use by default and some of the options it has.
See \code{vignette("slabinterval")} for a variety of examples of use.
}
