aKDE | R Documentation |
Modification of ggplot2::stat_density()
for kernel density estimates using a combination of the
Botev (2010) bandwidth selector and the Abramson (1982) adaptive kernel
bandwidth modifier.
stat_aKDE(
mapping = NULL,
data = NULL,
stat = "DensityAdaptive",
geom = "area",
position = "stack",
...,
from = NA,
to = NA,
bw = NA,
adjust = 1,
kernel = "gaussian",
n = 512,
adaptive = TRUE,
na.rm = FALSE,
bounds = c(-Inf, Inf),
show.legend = NA,
orientation = NA,
inherit.aes = TRUE
)
geom_aKDE(
mapping = NULL,
data = NULL,
stat = "DensityAdaptive",
position = "identity",
...,
na.rm = FALSE,
orientation = NA,
show.legend = NA,
inherit.aes = TRUE,
outline.type = "upper"
)
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
geom , stat |
Use to override the default connection between
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
... |
Other arguments passed on to
|
from , to |
the left and right-most points of the grid at which the density is to be estimated |
bw |
the bandwidth of the KDE. If |
adjust |
A multiplicate bandwidth adjustment. This makes it possible
to adjust the bandwidth while still using the a bandwidth estimator.
For example, |
kernel |
Kernel. See list of available kernels in |
n |
number of equally spaced points at which the density is to be
estimated, should be a power of two, see |
adaptive |
logical flag controlling if the adaptive KDE modifier of Abramson (1982) is used |
na.rm |
If |
bounds |
Known lower and upper bounds for estimated data. Default
|
show.legend |
logical. Should this layer be included in the legends?
|
orientation |
The orientation of the layer. The default ( |
inherit.aes |
If |
outline.type |
Type of the outline of the area; |
weight |
numeric vector of non-negative observation weights, hence of
same length as |
Algorithm for adaptive kernel is modified from IsoplotR. The
algorithm for the optimal kernel bandwidth is from provenance::botev()
.
data("sample")
example <- age_ICP(sample, zeta = c(0.1188, 0.0119))
# IsoplotR::kde(example$ages$t)
ggplot2::ggplot(data = example$ages, mapping = ggplot2::aes(x = t)) +
stat_aKDE(adaptive = TRUE) +
stat_aKDE(adaptive = FALSE, color = "red", fill = NA)
ggplot2::ggplot(
data = example$ages,
mapping = ggplot2::aes(x = t, weight = t / st)
) +
geom_aKDE(
ggplot2::aes(y = ggplot2::after_stat(scaled)),
kernel = "epanechnikov", fill = "steelblue", alpha = .75
) +
ggplot2::geom_histogram(
ggplot2::aes(y = ggplot2::after_stat(ncount)),
color = "grey", fill = "grey", alpha = .5
) +
ggplot2::geom_rug(alpha = 0.5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.