Last active
June 1, 2017 17:54
-
-
Save abikoushi/c798780f7a6ecd24ee12a0fa1aebc698 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
StatMA <- ggproto("StatMA", Stat, | |
required_aes = c("x", "y"), | |
compute_group = function(data, scales,windowsize) { | |
grid <- data.frame(x = data$x) | |
grid$y <- stats::filter(data$y, rep(1,windowsize)) / windowsize | |
grid | |
} | |
) | |
stat_ma <- function(mapping = NULL, data = NULL, geom = "line", | |
position = "identity", na.rm = FALSE, show.legend = NA, | |
inherit.aes = TRUE, windowsize = 7, ...) { | |
layer( | |
stat = StatMA, data = data, mapping = mapping, geom = geom, | |
position = position, show.legend = show.legend, inherit.aes = inherit.aes, | |
params = list(windowsize = windowsize, na.rm = na.rm, ...) | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment