method_kde_1d {ggdensity} | R Documentation |
Univariate kernel density HDR estimator
Description
Function used to specify univariate kernel density estimator
for get_hdr_1d()
and layer functions (e.g. geom_hdr_rug()
).
Usage
method_kde_1d(
bw = "nrd0",
adjust = 1,
kernel = "gaussian",
weights = NULL,
window = kernel
)
Arguments
bw |
the smoothing bandwidth to be used. The kernels are scaled such that this is the standard deviation of the smoothing kernel. (Note this differs from the reference books cited below, and from S-PLUS.)
The specified (or computed) value of |
adjust |
the bandwidth used is actually |
kernel , window |
a character string giving the smoothing kernel
to be used. This must partially match one of
|
weights |
numeric vector of non-negative observation weights,
hence of same length as |
Details
For more details on the use and implementation of the method_*_1d()
functions,
see vignette("method", "ggdensity")
.
Examples
df <- data.frame(x = rnorm(1e3, sd = 3))
ggplot(df, aes(x)) +
geom_hdr_rug(method = method_kde_1d()) +
geom_density()
# Details of the KDE can be adjusted with arguments to `method_kde_1d()`
ggplot(df, aes(x)) +
geom_hdr_rug(method = method_kde_1d(adjust = 1/5)) +
geom_density(adjust = 1/5)
ggplot(df, aes(x)) +
geom_hdr_rug(method = method_kde_1d(kernel = "triangular")) +
geom_density(kernel = "triangular")
# Can also be used with `get_hdr_1d()` for numerical summary of HDRs
res <- get_hdr_1d(df$x, method = method_kde_1d())
str(res)