I am trying to run following code as given in FPP3 book, however it is produces an error:-
fit <- gdppc %>% model(trend_model = TSLM(GDP_per_capita ~ trend()))
fit |>
forecast(h = "3 years") |>
filter(Country == "Sweden") |>
autoplot(gdppc) +
labs(y = "$US", title = "GDP per capita for Sweden")
This code produces the following error:-
Error in f(...) :
3 arguments passed to .Internal(is.unsorted) which requires 2
However, when I tweak it a little bit and do not pass any argument to autoplot function it produces the plot only for forecasted values. It does not show original data along with forecasted point values and prediction intervals as shown in the FPP3 book. Following is the code for reference:-
gdppc %>% model(trend_model = TSLM(GDP_per_capita ~ trend())) %>%
forecast(h = "5 years") %>%
filter(Country == "Australia") %>%
autoplot() +
labs(y = "Number of People", title = "Forecast for Aus GDPPC")
Can anyone explain why autoplot is not working with forecast object and help me to improve the code to get desired output of original values along with forecasted point values and prediction intervals as shown in the FPP3 book.