Learn R Programming

tidybayes (version 1.0.4)

geom_interval: Multiple probability interval plots (ggplot geom)

Description

Modified versions of geom_linerange and geom_linerangeh with default aesthetics designed for use with output from point_interval.

Usage

geom_interval(mapping = NULL, data = NULL, stat = "identity",
  position = "identity", ..., na.rm = FALSE, show.legend = NA,
  inherit.aes = TRUE)

geom_intervalh(mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE)

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.

stat

The statistical transformation to use on the data for this layer.

position

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

...

Other arguments passed to layer.

na.rm

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

show.legend

Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes.

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 behavior from the default plot specification, e.g. borders.

Details

geom_interval is a modified version of geom_linerange, and geom_intervalh is a modified version of geom_linerangeh. These geoms set some default aesthetics equal to the .lower, .upper, and .width columns generated by the point_interval family of functions, making them often more convenient than vanilla geom_linerange or geom_linerangeh when used with functions like median_qi, mean_qi, mode_hdi, etc.

Specifically, geom_interval acts as if its default aesthetics are aes(ymin = .lower, ymax = .upper, color = fct_rev(ordered(.width))). geom_intervalh acts as if its default aesthetics are aes(xmin = .lower, xmax = .upper, color = fct_rev(ordered(.width))).

See Also

See geom_lineribbon for a similar geom designed for curves plus probability bands. See geom_linerange and geom_linerangeh for the geoms these are based on.

Examples

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

data(RankCorr, package = "tidybayes")

RankCorr %>%
  spread_draws(u_tau[i]) %>%
  median_qi(.width = c(.5, .8, .95, .99)) %>%
  ggplot(aes(y = i, x = u_tau)) +
  geom_intervalh() +
  scale_color_brewer()

RankCorr %>%
  spread_draws(u_tau[i]) %>%
  median_qi(.width = c(.5, .8, .95, .99)) %>%
  ggplot(aes(x = i, y = u_tau)) +
  geom_interval() +
  scale_color_brewer()

# }

Run the code above in your browser using DataLab