我试图绘制时间序列图,我遇到了错误:

“不知道如何自动为data.frame类型的对象选择比例 . 默认为连续 . 错误:geom_line需要以下缺少美学:y . ”

你能帮我理解一下我的错误吗?以下是代码:

set.seed(37)

# Initialize the signal vector for the first model
s_t1 = data_frame(vector(mode = "numeric", length = 400))

# Create the signal vector for the first model
for (t in 1:400) {
  if (t <= 200) { # run if t is at most 200
    s_t1[t] = 0
    } else { # run if t is greater than 200
      s_t1[t] = 10*exp(-(t-200)/40)*cos(2*pi*t/4)
    }
}

# Create the white noise for the two models
w_t = data_frame(e = rnorm(400))

# Create the first model
y_t1 = s_t1 + w_t

# Initialize the signal vector for the second model
s_t2 = data_frame(vector(mode = "numeric", length = 400))

# Create the signal vector for the second model
for (t in 1:400) {
  if (t <= 200) { # run if t is at most 200
    s_t2[t] = 0
    } else { # run if t is greater than 200
      s_t2[t] = 10*exp(-(t-200)/400)*cos(2*pi*t/4)
    }
}

# Create the first model
y_t2 = s_t2 + w_t

s = cbind(s_t1, s_t2)
# Create the time series plot
sPlot = ggplot(data = s, aes(x = t, y = s)) +
  geom_line(stat = 'identity') +
  ggtitle('Signal Modulators') +
  ylab('Signal')
sPlot