stat_rollingkernel {ggh4x} | R Documentation |
A rolling kernel moves along one of the axes and assigns weights to datapoints depending on the distance to the kernel's location. It then calculates a weighted average on the y-values of the datapoints, creating a trendline. In contrast to (weighted) rolling averages, the interval between datapoints do not need to be constant.
stat_rollingkernel( mapping = NULL, data = NULL, geom = "line", position = "identity", ..., bw = "nrd", kernel = "gaussian", n = 256, expand = 0.1, na.rm = FALSE, orientation = "x", show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
geom |
Use to override the default geom ( |
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
... |
Other arguments passed on to |
bw |
A bandwidth, which can be one of the following:
|
kernel |
One of the following:
|
n |
An |
expand |
A |
na.rm |
If |
orientation |
A |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
A Layer ggproto object.
stat_rollingkernel()
understands the following
aesthetics (required aesthetics are in bold)
x
y
group
x
A sequence of ordered x positions.
y
The weighted value of the rolling kernel.
weight
The sum of weight strengths at a position.
scaled
The fraction of weight strengths at a position. This is
the same as weight / sum(weight)
by group.
ggplot(mpg, aes(displ, hwy, colour = class)) + geom_point() + stat_rollingkernel() # The (scaled) weights can be used to emphasise data-dense areas ggplot(mpg, aes(displ, hwy, colour = class)) + geom_point() + stat_rollingkernel(aes(alpha = after_stat(scaled)))