【问题标题】:Add a function to ggplot向ggplot添加一个函数
【发布时间】:2021-03-26 09:51:33
【问题描述】:

我想添加这个功能
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")

【问题讨论】:

  • 还有什么问题?
  • 如何在绘图脚本中添加函数
  • 你能生成一些虚拟数据或使用 R 中包含的应该适合绘图/函数的标准数据集吗?

标签: r function ggplot2


【解决方案1】:

由于您没有提供任何样本数据,以下是基于一些随机虚拟数据的解决方案:

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")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-21
    • 2020-03-09
    • 2018-01-07
    • 2016-03-04
    • 2017-12-22
    • 2018-08-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多