Hi all,
I get this weird error message when trying to add a layer to my ggplot. It seems fine when rendering the reprex, but when running on my R console (I'm running RStudio Version 1.2.5001 on Mac OS Mojave 10.14.3) I get this:
"Error: Invalid input: date_trans works with objects of class Date only"
Does anyone now why this happens and why it seems fine on the reprex?
Here's the code:
#load packages
library(tidyverse)
library(astsa)
library(ggfortify)
library(gridExtra)
#>
#> Attaching package: 'gridExtra'
#> The following object is masked from 'package:dplyr':
#>
#> combine
library(fpp2)
#> Loading required package: forecast
#> Registered S3 method overwritten by 'xts':
#> method from
#> as.zoo.xts zoo
#> Registered S3 method overwritten by 'quantmod':
#> method from
#> as.zoo.data.frame zoo
#> Registered S3 methods overwritten by 'forecast':
#> method from
#> autoplot.Arima ggfortify
#> autoplot.acf ggfortify
#> autoplot.ar ggfortify
#> autoplot.bats ggfortify
#> autoplot.decomposed.ts ggfortify
#> autoplot.ets ggfortify
#> autoplot.forecast ggfortify
#> autoplot.stl ggfortify
#> autoplot.ts ggfortify
#> fitted.ar ggfortify
#> fitted.fracdiff fracdiff
#> fortify.ts ggfortify
#> residuals.ar ggfortify
#> residuals.fracdiff fracdiff
#>
#> Attaching package: 'forecast'
#> The following object is masked from 'package:astsa':
#>
#> gas
#> Loading required package: fma
#>
#> Attaching package: 'fma'
#> The following objects are masked from 'package:astsa':
#>
#> chicken, sales
#> Loading required package: expsmooth
#>
#> Attaching package: 'fpp2'
#> The following object is masked from 'package:astsa':
#>
#> oil
library(GGally)
#> Registered S3 method overwritten by 'GGally':
#> method from
#> +.gg ggplot2
#>
#> Attaching package: 'GGally'
#> The following object is masked from 'package:fma':
#>
#> pigs
#> The following object is masked from 'package:dplyr':
#>
#> nasa
library(reprex)
library(forecast)
#attach data
economy_data=econ5
#unemployment rate model accuracy using the validation test set approach
unemp_timeseries=ts(economy_data[,1], start = 1948, frequency = 4)
train_unemp= window(unemp_timeseries, start=c(1948,1), end=c(1977,4))
test_unemp= window(unemp_timeseries, start = c(1978,1))
#fit model
naive_train=naive(train_unemp, h=100)
#superimpose predictions to data
autoplot(unemp_timeseries) + autolayer(naive_train, series="Naive", PI=FALSE) + xlab("Years") + ylab("Unemployment rate predictions") + ggtitle("Forecast unemployment")
Created on 2019-12-17 by the reprex package (v0.3.0)
Thanks!
Ramon