autoplot.kde {weird} | R Documentation |
Produce ggplot of densities in 1 or 2 dimensions
Description
Produce ggplot of densities in 1 or 2 dimensions
Usage
## S3 method for class 'kde'
autoplot(
object,
prob = seq(9)/10,
fill = FALSE,
show_hdr = FALSE,
show_points = FALSE,
show_mode = FALSE,
show_lookout = FALSE,
color = "#00659e",
palette = hdr_palette,
alpha = ifelse(fill, 1, min(1, 1000/NROW(object$x))),
...
)
Arguments
object |
Probability density function as estimated by |
prob |
Probability of the HDR contours to be drawn (for a bivariate plot only). |
fill |
If |
show_hdr |
If |
show_points |
If |
show_mode |
If |
show_lookout |
If |
color |
Color used for mode and HDR contours. If |
palette |
Color palette function to use for HDR filled regions
(if |
alpha |
Transparency of points. When |
... |
Additional arguments are currently ignored. |
Details
This function produces a ggplot of the density estimate produced by ks::kde()
.
For univariate densities, it produces a line plot of the density function, with
an optional ribbon showing some highest density regions (HDRs) and/or the observations.
For bivariate densities, it produces a contour plot of the density function, with
the observations optionally shown as points.
The mode can also be drawn as a point with the HDRs.
For bivariate densities, the combination of fill = TRUE
, show_points = TRUE
,
show_mode = TRUE
, and prob = c(0.5, 0.99)
is equivalent to an HDR boxplot.
For univariate densities, the combination of show_hdr = TRUE
, show_points = TRUE
,
show_mode = TRUE
, and prob = c(0.5, 0.99)
is equivalent to an HDR boxplot.
Value
A ggplot object.
Author(s)
Rob J Hyndman
Examples
# Univariate density
c(rnorm(500), rnorm(500, 4, 1.5)) |>
kde() |>
autoplot(show_hdr = TRUE, prob= c(0.5, 0.95), color = "#c14b14")
ymat <- tibble(y1 = rnorm(5000), y2 = y1 + rnorm(5000))
ymat |>
kde(H = kde_bandwidth(ymat)) |>
autoplot(show_points = TRUE, alpha = 0.1, fill = TRUE)