View source: R/gg_density_layer.R
| gg_density_layer | R Documentation |
Add ggplot layer of densities from distributional objects in 1 dimension
gg_density_layer(object, scale = 1, ngrid = 501, ...)
object |
distribution object from the distributional package or
|
scale |
Scaling factor for the density function. |
ngrid |
Number of grid points to use for the density function. |
... |
Additional arguments are passed to |
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.
A ggplot layer
Rob J Hyndman
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.