无法预测ggplot2中的X轴错误

时间:2018-09-09 20:46:44

标签: r ggplot2

我有来自Google Analytics(分析)的数据,其中包含500天每天的网站访问量。 我能够将其分为80%的训练和20%的测试[400天与100天]。 运行预测模型后,当我尝试绘制图表时,出现以下错误:

  

无法预测x轴

这是从GA提取数据的脚本

#Pull data from GA
gadata <- google_analytics (viewId = 12345657, 
                           date_range = c(Sys.Date()-500, Sys.Date()-1),
                           metrics = ("sessions"),
                           dimensions = ("date"),
                           anti_sample = TRUE)

这是将数据转换为TS的脚本

#Convert dataframe to TS
library(xts)
ts_gadata <- xts(gadata[,-1], order.by=as.Date(gadata[,1], "%y/%m/%d"))

这是划分为训练/测试的脚本

#split GA data into training & test
ts_gadata_train <- window(ts_gadata, start="2017-04-26", end = "2018-05-31")
ts_gadata_test <- window(ts_gadata, start="2018-06-01")

以下是用于运行模型/准确性的脚本

#split GA data into training & test
ts_gadata_train <- window(ts_gadata, start="2017-04-26", end = "2018-05-31")
ts_gadata_test <- window(ts_gadata, start="2018-06-01")
#models
meanm <- meanf(ts_gadata_train, h=100)
naivem <- naive(ts_gadata_train, h=100)
driftm <- rwf(ts_gadata_train, h=100, drift = T)
#accuracy of models
accuracy(meanm,ts_gadata_test)
accuracy(naivem,ts_gadata_test)
accuracy(driftm,ts_gadata_test)

这就是尝试绘制错误的地方

#plot of models
autoplot(subset(ts_gadata, end = 500)) +
  autolayer(meanm, PI=FALSE, series="Mean") +
  autolayer(naivem, PI=FALSE, series="Naïve") +
  autolayer(driftm, PI=FALSE, series="Drift") +
  xlab("Day") + ylab("Sessions to website") +
  ggtitle("Daily sessions to website") +
  guides(colour=guide_legend(title="Forecast"))

从控制台将错误显示为jpg

enter image description here

对此有任何帮助吗? 谢谢。

0 个答案:

没有答案