Is this supposed to be a reprex? I don't see where train_tbl is defined. On Fri, Jun 14, 2019 at 10:30 PM Bill Poling <bill.pol...@zelis.com> wrote:
> #RStudio Version 1.2.1335 > sessionInfo() > #R version 3.5.3 (2019-03-11) > #Platform: x86_64-w64-mingw32/x64 (64-bit) > #Running under: Windows >= 8 x64 (build 9200) > > Hello I am fitting an Arima model and all appears to go well until I get > to the ggplot, (again, lots of laughs). > Deja Vu all over again! (God I hope it's not a typo!) > > The error at the point of the plot is: > # Don't know how to automatically pick scale for object of type function. > Defaulting to continuous. > # Error: All columns in a tibble must be 1d or 2d objects: > # * Column `x` is function > > I hope someone recognizes my problem. > > Thank you for any assistance. > > #Here is the code and particulars of the data being plotted > > #Fit the arima model > > fit_arima2 <- train_tbl %>% > tk_ts(select = NetEditRev, frequency = 364) %>% > Arima(order = c(1,0,2), > seasonal=c(0,1,0), > include.drift = TRUE) > > #Forecast with Sweep Functions---- > > fcast_arima_tbl <- forecast(fit_arima2, h = nrow(test_tbl)) %>% > sw_sweep(timetk_idx = TRUE, rename_index = "date") > > #Save the DF > > fs::dir_create("00_model") > > fcast_arima_tbl %>% write_rds("00_model/fcast_arima_tbl.rds") > > fcast_arima_tbl1 <- read_rds("00_model/fcast_arima_tbl.rds") > > head(fcast_arima_tbl1) > > # A tibble: 6 x 7 > date key NetEditRev lo.80 lo.95 hi.80 hi.95 > <date> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> > 1 2017-01-01 actual -923. NA NA NA NA > 2 2017-01-02 actual 19222. NA NA NA NA > 3 2017-01-03 actual -8397. NA NA NA NA > 4 2017-01-04 actual 37697. NA NA NA NA > 5 2017-01-05 actual 46075. NA NA NA NA > 6 2017-01-06 actual 38329. NA NA NA NA > > str(fcast_arima_tbl1) > Classes 'tbl_df', 'tbl' and 'data.frame':892 obs. of 7 variables: > $ date : Date, format: "2017-01-01" "2017-01-02" "2017-01-03" > "2017-01-04" ... > $ key : chr "actual" "actual" "actual" "actual" ... > $ NetEditRev: num -923 19222 -8397 37697 46075 ... > $ lo.80 : num NA NA NA NA NA NA NA NA NA NA ... > $ lo.95 : num NA NA NA NA NA NA NA NA NA NA ... > $ hi.80 : num NA NA NA NA NA NA NA NA NA NA ... > $ hi.95 : num NA NA NA NA NA NA NA NA NA NA ... > > #Plot the model > > g4 <- fcast_arima_tbl1 %>% > ggplot(aes(date, NetEditRev, color = key)) + > geom_point(data = test_tbl %>% mutate(key = "actual")) + > geom_point(alpha = 0.5) + > theme_tq() + > scale_color_tq() + > labs(title = "ARIMA(1,0,2)(0,1,0 with Drift For Net Edit Revenue") > > g4 > # Don't know how to automatically pick scale for object of type function. > Defaulting to continuous. > # Error: All columns in a tibble must be 1d or 2d objects: > # * Column `x` is function > > ggplotly(g4) %>% > layout(xaxis = list(rangeslider = list(type = "date"))) > # Don't know how to automatically pick scale for object of type function. > Defaulting to continuous. > # Error: All columns in a tibble must be 1d or 2d objects: > # * Column `x` is function > > > #Alternative changes that I have tried based on google searches, but have > their own errors. > > # g4 <- fcast_arima_tbl1 %>% > # ggplot(aes(date, NetEditRev, color = key)) + > # geom_point(data = test_tbl %>% filter(key = "actual")) + #Try using > filter > # geom_point(alpha = 0.5) + > # theme_tq() + > # scale_color_tq() + > # labs(title = "ARIMA(1,0,2)(0,1,0 with Drift For Net Edit Revenue") > # #Error: `key` (`key = "actual"`) must not be named, do you need `==`? > # > # g4 <- fcast_arima_tbl1 %>% > # ggplot(aes(date, NetEditRev, color = key)) + > # geom_point(data = test_tbl %>% filter(key == "actual")) + #Try using > filter with == > # geom_point(alpha = 0.5) + > # theme_tq() + > # scale_color_tq() + > # labs(title = "ARIMA(1,0,2)(0,1,0 with Drift For Net Edit Revenue") > # #Error: object 'key' not found > # > # g4 <- fcast_arima_tbl1 %>% > # ggplot(aes(date, NetEditRev, color = key)) + > # geom_point(data = test_tbl) + > # filter(fcast_arima_tbl1$key = "actual") + #Try filter with > fcast_arima_tbl1$key and repositioned with + > # geom_point(alpha = 0.5) + > # theme_tq() + > # scale_color_tq() + > # labs(title = "ARIMA(1,0,2)(0,1,0 with Drift For Net Edit Revenue") > # #Error: Cannot add ggproto objects together. Did you forget to add this > object to a ggplot object? > > > Confidentiality Notice This message is sent from Zelis. ...{{dropped:13}} > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.