geom_distribution: Draw a probability density function as a continuous curve

GeomDistributionR Documentation

Draw a probability density function as a continuous curve

Description

Computes and draws a probability density function as a continuous curve.

Usage

geom_distribution(
  mapping = NULL,
  data = NULL,
  stat = "distribution",
  position = "identity",
  ...,
  fill = NA,
  outline.type = "upper",
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)

stat_distribution(
  mapping = NULL,
  data = NULL,
  geom = "ribbon",
  position = "identity",
  ...,
  fun,
  xlim = NULL,
  n = 500,
  p_limit = 0.001,
  location = 0,
  fill = NA,
  alpha = 0.3,
  outline.type = "upper",
  color = "black",
  size = 0.5,
  args = list(),
  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

Ignored by stat_distribution(), do not use.

stat

The statistical transformation to use on the data for this layer, as a string.

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.

fill

Color of fill under the curve. No fill (NA) by default.

outline.type

Type of the outline of the area; "both" draws both the upper and lower lines, "upper"/"lower" draws the respective lines only. "full" draws a closed polygon around the area.

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

The geometric object to use display the data

fun

Function to use. A quoted or character name referencing a probability density function; see examples. Must be vectorised.

xlim

Optionally, restrict the range of the function to this range.

n

Number of points to interpolate along the main body of the probability density.

p_limit

The lower probability density limit to plot.

location

Where to shift the origin. For probability density functions that do not inherently allow for changing their location, this allows that shift.

alpha

Fill color transparency, if applicable.

color

Color of the line.

size

Size of the line.

args

List of additional arguments passed on to the function defined by fun.

Aesthetics

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

  • x or y

  • ymin or xmin

  • ymax or xmax

  • alpha

  • colour

  • fill

  • group

  • linetype

  • size

Learn more about setting these aesthetics in vignette("ggplot2-specs").

Computed variables

stat_distribution() computes the following variables:

x

x values along a grid where the probability density is at least p_limit

y

value of the probability density function evaluated at corresponding x

Examples


# geom_distribution() is useful for overlaying probability distributions
set.seed(1234)
ggplot(data.frame(x = rnorm(100)), aes(x)) +
  geom_density() +
  geom_distribution(fun = dnorm, color = "red")


ryanraaum/plotpriors documentation built on March 31, 2022, 3:24 a.m.