GeomPosterior: Geom for plotting posterior distributions

Description Usage Arguments Functions Aesthetics Computed Variables Examples

Description

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.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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)

Arguments

mapping

Set of aesthetic mappings created by aes() or aes_(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

data

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.

stat

Used to override the default connection between geom_posterior and stat_density_ci.

position

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.

draw_ci

geom. Toggles drawing of the confidence interval lines and segments.

draw_sd

geom. Toggles drawing of the standard deviation interval lines and segments.

midline

geom. Color of the vertical, center line. Set to NA to omit the line.

brighten

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

mirror

geom. Show standard densities (mirror=FALSE) or horizontal violin densities (mirror=TRUE).

interp_thresh

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.

na.rm

If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed.

show.legend

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.

inherit.aes

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().

geom

Use to override the default connection between geom_posterior and stat_density_ci

center_stat

stat. character string of method to compute the distribution's central tendency, such as "median", "mean", or "mode".

ci_width

stat. Width of the distribution's confidence/highest density interval, e.g., 0.95

interval_type

stat. method of computing the interval, either "hdi" or "ci"

bw

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.

adjust

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

Kernel. See list of available kernels in density().

cut

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.

n

number of equally spaced points at which the density is to be estimated, should be a power of two, see density() for details

trim

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().

Functions

Aesthetics

geom_posterior understands the following aesthetics (required aesthetics are in bold):

Computed Variables

stat_density_ci:

position_spread

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
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))

ggdistribute documentation built on May 2, 2019, 10:25 a.m.