This geom may be used to plot the density of any type of numeric variable but the displayed intervals may not be informative if the distribution deviates too much from a unimodal, symmetric distribution.
geom_posterior(mapping = NULL, data = NULL, stat = "DensityCI",
position = "spread", ..., draw_ci = TRUE, draw_sd = TRUE,
midline = "#767698", brighten = TRUE, mirror = FALSE,
interp_thresh = NULL, na.rm = FALSE, show.legend = NA,
inherit.aes = TRUE)stat_density_ci(mapping = NULL, data = NULL, geom = "Posterior",
position = "spread", ..., center_stat = "median", ci_width = 0.9,
interval_type = "ci", bw = "nrd0", adjust = 1,
kernel = "gaussian", cut = 1, n = 1024, trim = 0.01,
na.rm = FALSE, show.legend = NA, inherit.aes = TRUE)
The data to be displayed in this layer. There are three options:
If NULL
, the default, the data is inherited from the plot
data as specified in the call to ggplot()
.
A data.frame
, or other object, will override the plot
data. All objects will be fortified to produce a data frame. See
fortify()
for which variables will be created.
A function
will be called with a single argument,
the plot data. The return value must be a data.frame
, and
will be used as the layer data.
Used to override the default connection between geom_posterior
and stat_density_ci
.
Position adjustment, either as a string, or the result of a call to a position adjustment function.
Other arguments passed on to layer()
. These are
often aesthetics, used to set an aesthetic to a fixed value, like
colour = "red"
or size = 3
. They may also be parameters
to the paired geom/stat.
geom. Toggles drawing of the confidence interval lines and segments.
geom. Toggles drawing of the standard deviation interval lines and segments.
geom. Color of the vertical, center line. Set to NA
to omit the line.
geom. Numeric adjustments to the fill color. A value above 1 increases brightness, below decreases. Should be of length 1 or 5, otherwise values are recycled
geom. Show standard densities (mirror=FALSE
) or horizontal
violin densities (mirror=TRUE
).
geom. If the number of samples used to estimate the density is low, this will result in gaps between segments. This argument decides to interpolate points based on gap proportion for a segment.
If FALSE
, the default, missing values are removed with
a warning. If TRUE
, missing values are silently removed.
logical. Should this layer be included in the legends?
NA
, the default, includes if any aesthetics are mapped.
FALSE
never includes, and TRUE
always includes.
It can also be a named logical vector to finely select the aesthetics to
display.
If 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. borders()
.
Use to override the default connection between geom_posterior
and stat_density_ci
stat. character string of method to compute the
distribution's central tendency, such as "median"
, "mean"
, or "mode"
.
stat. Width of the distribution's confidence/highest density interval, e.g., 0.95
stat. method of computing the interval, either "hdi"
or "ci"
The smoothing bandwidth to be used. If numeric, the standard
deviation of the smoothing kernel. If character, a rule to choose the
bandwidth, as listed in stats::bandwidth. If the bandwidth character
starts wit a "."
(e.g., ".nrd0"
), then the average bandwidth will be
calculated among all groups in a panel and used for each density estimate.
A multiplicate bandwidth adjustment. This makes it possible
to adjust the bandwidth while still using the a bandwidth estimator.
For example, adjust = 1/2
means use half of the default bandwidth.
Kernel. See list of available kernels in density()
.
The values to use for the start and end of the density estimation
are cut
bandwidths (e.g., 0.5*bw
) beyond the extremes of the data.
This allows the estimated density to drop to approximately zero at the
extremes.
number of equally spaced points at which the density is to be
estimated, should be a power of two, see density()
for
details
If a value between 0 and 1 is given, trim the tails of x
by
some proportion according to trim
. If NULL
or NA
, don't trim the
tails. See trim_ends()
.
geom_posterior
: geom_posterior Posterior Geom
stat_density_ci
: stat_density_ci Computes a distribution density and
confidence intervals for each group
geom_posterior
understands the following aesthetics (required aesthetics
are in bold):
x
y
xmin
xmax
alpha - colour
fill
group
linetype
size
weight
stat_density_ci:
density: density estimate from stats::density
scaled: Normalized density values: density / max(density)
count: Number of samples at density level: (density / sum(density)) * n
xmin: minimum value of x
from the data
cil: cil cutoff value based on ci_width
sdl: central value minus 1 sd of x
mid: value of central tendency
sdu: central value plus 1 sd of x
ciu: ciu cutoff value based on ci_width
xmax: maximum value of x
from the data
position_spread
ymin: minimum value of y
for each group in a panel.
ymax: maximum value of y
for each group in a panel.
# NOT RUN {
library(ggplot2)
x <- data_normal_sample(mu = c(-1, 0, 1), n = 500)
p <- ggplot(x, aes(x = value))
p + geom_posterior()
p + geom_posterior(aes(y = Condition))
p + geom_posterior(aes(y = GroupScore, fill = Condition))
p + geom_posterior(aes(y = GroupScore, fill = Group),
brighten = c(1.3, 0, -1.3),
position = position_spread(
height=0.5,
padding = 0))
# }
Run the code above in your browser using DataLab