plot.kdensity: Plot, Lines and Points Methods for Kernel Density Estimation

View source: R/generics.R

plot.kdensityR Documentation

Plot, Lines and Points Methods for Kernel Density Estimation

Description

The plot method for kdensity objects.

Usage

## S3 method for class 'kdensity'
plot(x, range = NULL, plot_start = FALSE, zero_line = TRUE, grid = "auto", ...)

## S3 method for class 'kdensity'
lines(
  x,
  range = NULL,
  plot_start = FALSE,
  zero_line = TRUE,
  grid = "auto",
  ...
)

## S3 method for class 'kdensity'
points(
  x,
  range = NULL,
  plot_start = FALSE,
  zero_line = TRUE,
  grid = "auto",
  ...
)

Arguments

x

a kdensity object.

range

range of x values.

plot_start

logical; if TRUE, plots the parametric start instead of the kernel density estimate.

zero_line

logical; if TRUE, add a base line at y = 0.

grid

Evaluation backend. "auto" uses the fastest verified backend: FFT for Gaussian and Gaussian-copula kernels, and exact evaluation otherwise. "exact" always retains direct evaluation and "fft" explicitly requests the approximate backend supported by kdensity_grid().

...

further plotting parameters.

Value

None.

See Also

kdensity()

Examples

## Using the data set "precip" to eye-ball the similarity between
## a kernel fit, a parametric fit, and a kernel with parametric start fit.
kde_gamma <- kdensity(precip, kernel = "gaussian", start = "gamma")
kde <- kdensity(precip, kernel = "gaussian", start = "uniform")

plot(kde_gamma, main = "Annual Precipitation in US Cities")
lines(kde_gamma, plot_start = TRUE, lty = 2)
lines(kde, lty = 3)
rug(precip)

kdensity documentation built on Oct. 28, 2026, 5:06 p.m.