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.
Perhaps you've loaded some other package that is over-writing the autoplot method. Try running your code in a new session with only library(fpp3) loaded.
This looks like a potential R installation issue. My best guess is that you should try re-installing (and updating) R.
The error is suggesting that the internal function is.unsorted expects 2 arguments, however this is not the case. I'm hopeful that re-installing R will fix this internal function so that it expects the 3 arguments that it usually does.
I am having the same problem, however it still occurs after reinstalling R and RStudio. I am using R in windows, but the problem also happened using WSL rstudio-server. Both in R 4.3.1.
Is there a workaround to get both the data and the forecast with autoplot (or ggplot)?