gg_density_layer: Add ggplot layer of densities from distributional objects in...

View source: R/gg_density_layer.R

gg_density_layerR Documentation

Add ggplot layer of densities from distributional objects in 1 dimension

Description

Add ggplot layer of densities from distributional objects in 1 dimension

Usage

gg_density_layer(object, scale = 1, ngrid = 501, ...)

Arguments

object

distribution object from the distributional package or dist_kde()

scale

Scaling factor for the density function.

ngrid

Number of grid points to use for the density function.

...

Additional arguments are passed to geom_line.

Details

This function adds a ggplot layer of a density from a distributional object. For univariate densities, it adds a line plot of the density function. For bivariate densities, it adds a contour plot of the density function.

Value

A ggplot layer

Author(s)

Rob J Hyndman

Examples

dist_mixture(
  dist_normal(-2, 1),
  dist_normal(2, 1),
  weights = c(1 / 3, 2 / 3)
) |>
  gg_density() +
  gg_density_layer(dist_normal(-2, 1), linetype = "dashed", scale = 1 / 3) +
  gg_density_layer(dist_normal(2, 1), linetype = "dashed", scale = 2 / 3)

weird documentation built on Jan. 27, 2026, 9:06 a.m.