Learn R Programming

tidybayes (version 0.12.1.9000)

geom_halfeyeh: Half-eye plots of densities with point estimates and intervals (ggplot geom)

Description

Generates a combination geom_density_ridges and geom_pointrangeh (using stat_summaryh) representing the density, point estimates, and credible interval. Useful for representing posterior estimates from Bayesian samplers; in that context the mirrored verison is variously called an eye plot, a raindrop plot, or a violin plot; hence "half-eye" for this plot.

Usage

geom_halfeyeh(mapping = NULL, data = NULL, position = "identity",
  trim = TRUE, scale = "area", relative_scale = 1, fill = NULL,
  density.color = NA, ..., point_interval = median_qi, fun.data = NULL,
  fun.args = list(), .prob = c(0.66, 0.95), color = NULL, size = NULL,
  size_domain = NULL, size_range = NULL, fatten_point = NULL)

Arguments

mapping

The aesthetic mapping, usually constructed with aes or aes_string. Only needs to be set at the layer level if you are overriding the plot defaults.

data

A layer specific dataset - only needed if you want to override the plot defaults.

position

Passed to geom_density_ridges. The position adjustment to use for overlapping points on this layer.

trim

If TRUE (default), trim the tails of the density to the range of the data. If FALSE, don't trim the tails.

scale

If "area" (default), all densities have the same area (before trimming the tails). If "count", areas are scaled proportionally to the number of observations. If "width", all densities have the same maximum width/height.

relative_scale

A relative scaling factor to determine how much of the available space densities are scaled to fill: if 1, all available space is filled.

fill

Fill color of the density.

density.color

Outline color of the density. The default, NA, suppresses the density outline. Set to another value to set the density outline color manually, or set to NULL if you want the outline color of the density to be determined by the aesthetic mapping.

...

Currently unused.

point_interval

A function that when given a vector should return a data frame with variables y, ymin, ymax, and .prob; or x, xmin, xmax, and .prob. Either is acceptable: output will be converted into the x-based aesthetics geom_halfeyeh. See the point_interval family of functions.

fun.data

Similar to point_interval, for compatibility with stat_summary. Note: if the summary function is passed using fun.data, the x and y-based aesthetics are not converted to the correct form automatically.

fun.args

Optional arguments passed to fun.data.

.prob

The .prob argument passed to fun.data.

color

Passed to stat_pointintervalh. Color of the point estimate and credible interval.

size

Passed to stat_pointintervalh. Line weight of the point estimate and credible interval.

size_domain

The minimum and maximum of the values of the size aesthetic that will be translated into actual sizes drawn according to size_range (see the documentation for that parameter, below.)

size_range

This geom scales the raw size aesthetic values, as they tend to be too thick when using the default settings of scale_size_continuous, which give sizes with a range of c(1, 6). The size_domain value indicates the input domain of raw size values (typically this should be equal to the value of the range parameter of the scale_size_continuous function), and size_range indicates the desired output range of the size values (the min and max of the actual sizes used to draw intervals).

fatten_point

A multiplicative factor used to adjust the size of the point relative to the size of the thickest line.

Details

A half-eye plot is a compact visual summary of the distribution of some samples, used (under various names and with subtle variations) to visualize posterior distributions in Bayesian inference. This instantiation is a combination of a density plot, point estimate, and credible interval. geom_halfeyeh() is equivalent to geom_density_ridges() + stat_summaryh() with some reasonable defaults, including color choices and the use of median with 95% and 66% quantile intervals.

See Also

See geom_eye and geom_eyeh for the mirrored-density (full "eye") versions. See geom_density_ridges and stat_summaryh for the geoms this function is based on.

Examples

Run this code
# NOT RUN {
library(magrittr)
library(ggplot2)

data(RankCorr, package = "tidybayes")

RankCorr %>%
  spread_samples(u_tau[i]) %>%
  ggplot(aes(y = i, x = u_tau)) +
  geom_halfeyeh()

# }

Run the code above in your browser using DataLab