r-向ggplot添加一个函数



我想添加此函数
ma <- function(x,n=11){filter(x,rep(1/n,n),method = "convolution", sides=2)}

`
到我的数据:

ggplot(data, aes(y=volume, x=time)) +
geom_line(color= "black", size=0.2, alpha=0.9) +
theme_classic() +
ggtitle(" Volume")

由于您没有提供任何样本数据,因此这里有一个基于一些随机伪数据的解决方案:

library(ggplot2)
ma <- function(x,n=11){filter(x,rep(1/n,n),method = "convolution", sides=2)}
x <- runif(1000)
data = data.frame(time = x, volume <- ma(x))
ggplot(data, aes(y=volume, x=time)) +
geom_line(color= "black", size=0.2, alpha=0.9) +
theme_classic() +
ggtitle(" Volume")

最新更新