在时间序列图中显示参与者移动平均线的中位数

问题描述 投票:0回答:0

我在 R 中处理时间序列数据并且对它很陌生。我有来自 18 名参与者的数据(刚好超过 24 小时),我为这些数据计算了一个中心移动平均值。因此,所需的图显示了每个参与者的 y 变量如何随时间变化。这是我的代码:

p <- ggplot(data = dftotal, aes(time, ma_data)) +
  geom_line(aes(color = Participant), size = 0.8) +
  labs(y = "Activity levels", x = "Time") + 
  date_labels = "%H:00", limits = lims, expand = c(0, 0)) +
  theme_classic()

其中 ma_data 是参与者活动的移动平均值。

现在我想在此图中添加一条线,显示这些移动平均线的中位数 + 四分位数范围线。我试过:

p + stat_summary(fun.data ="median", geom = "line")

我得到the following plot, which I don't understand

r ggplot2 time-series median moving-average
© www.soinside.com 2019 - 2024. All rights reserved.