geom_interval: Line plot visualising intervals of a distribution

View source: R/geom_fan.R

geom_intervalR Documentation

Line plot visualising intervals of a distribution

Description

For every value of x, computes quantiles of y and uses these to plot intervals containing increasing proportions of the total density of y. Boundaries of intervals are mapped to linetype. Quantiles can also be precomputed and mapped to the aesthetic quantile. This function is designed with the need to summarise MCMC posterior distributions in mind.

Usage

geom_interval(mapping = NULL, data = NULL, stat = "interval_fctr",
  position = "identity", intervals = c(0, 50, 90)/100,
  lineend = "butt", linejoin = "round", linemitre = 1,
  arrow = NULL, 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

Use to override the default use of stat_interval

position

Position adjustment, either as a string, or the result of a call to a position adjustment function.

intervals

specify the collection of intervals to be represented in the fan.

lineend

Line end style (round, butt, square).

linejoin

Line join style (round, mitre, bevel).

linemitre

Line mitre limit (number greater than 1).

arrow

Arrow specification, as created by grid::arrow().

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

...

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.

Aesthetics

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

  • x

  • y

  • quantile

  • group

  • colour

  • size

See Also

stat_summary Summarises y at each value of x stat_quantile Uses quantile regression to predict quantiles geom_fan Plot intervals on a continuous colour scale

Examples


library(ggplot2)
# Basic use. The data frame must have multiple y values for each
# x
ggplot(fake_df, aes(x=x,y=y)) +geom_interval()


# use precomputed quantiles - reducing storage requirements.
intervals = c(0,50,90)/100
fake_q <- calc_quantiles(fake_df, intervals=intervals)
# intervals in geom_fan must be the same as used to compute quantiles.
ggplot(fake_q, aes(x=x,y=y, quantile=quantile)) +
 geom_interval(intervals=intervals)



jasonhilton/ggfan documentation built on Sept. 17, 2023, 5:47 a.m.