geom_movmean | R Documentation |
geom_movmean
geom_movmean(
mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
...,
halfwin = 3,
show.diff = FALSE,
na.rm = FALSE,
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 |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
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
|
halfwin |
halfwin of movmean, |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
library(data.table)
library(ggplot2)
data("GPP_US_MMS")
dat = melt(GPP_US_MMS[, .(date, SM, GPP)], "date")
ggplot(dat, aes(date, value)) +
geom_line() +
geom_movmean(halfwin = 5, linewidth = 1, alpha = 0.7, color = "pink") +
# geom_movmean(halfwin = 5, show.diff=TRUE, linewidth = 0.2, alpha = 0.7, color = "red") +
geom_spike(halfwin = 2, sd.times = 6, color = "red", verbose = TRUE) +
# geom_spike(halfwin = 5, trs = 3, color = "blue") +
facet_wrap(~variable, scales = "free_y")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.