[R] FW: Help with a third ggplot error

Bill Poling B|||@Po||ng @end|ng |rom ze||@@com
Sat Jun 15 22:18:18 CEST 2019


So I changed it to date2.

fcast_arima_tbl <- forecast(fit_arima2, h = nrow(test_tbl)) %>%
  sw_sweep(timetk_idx = TRUE, rename_index = "date2")

head(fcast_arima_tbl,n=10)
# A tibble: 10 x 7
date2      key    NetEditRev lo.80 lo.95 hi.80 hi.95 <------Date2
   <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
 7 2017-01-07 actual     3111.     NA    NA    NA    NA
 8 2017-01-08 actual       21.4    NA    NA    NA    NA
 9 2017-01-09 actual    63570.     NA    NA    NA    NA
10 2017-01-10 actual    50777      NA    NA    NA    NA

Then I save it
fcast_arima_tbl %>% write_rds("00_model/fcast_arima_tbl.rds")

Then I read it back out as fcast_arima_tbl1
fcast_arima_tbl1 <- read_rds("00_model/fcast_arima_tbl.rds")

head(fcast_arima_tbl1)

head(fcast_arima_tbl1, n=10)
# A tibble: 10 x 7
   date2      key    NetEditRev lo.80 lo.95 hi.80 hi.95 <------Date2
   <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
 7 2017-01-07 actual     3111.     NA    NA    NA    NA
 8 2017-01-08 actual       21.4    NA    NA    NA    NA
 9 2017-01-09 actual    63570.     NA    NA    NA    NA
10 2017-01-10 actual    50777      NA    NA    NA    NA

However, when I try the plot again I get new error? Error in FUN(X[[i]], ...) : object 'date2' not found

fcast_arima_tbl1 %>%
+   ggplot(aes(date2, 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")
Error in FUN(X[[i]], ...) : object 'date2' not found

Now I remain confused

However, I sure appreciate everyone's time, thank you.

WHP

-----Original Message-----
From: Bill Poling
Sent: Saturday, June 15, 2019 4:00 PM
To: Rui Barradas <ruipbarradas using sapo.pt>; Richard M. Heiberger <rmh using temple.edu>
Cc: r-help (r-help using r-project.org) <r-help using r-project.org>; Eric Berger <ericjberger using gmail.com>; Bill Poling <Bill.Poling using zelis.com>
Subject: RE: [R] Help with a third ggplot error

Oh, yikes! Rui you are right.

1st I do this:

fit_arima2 <- train_tbl %>%
  tk_ts(select = NetEditRev, frequency = 364) %>%
  Arima(order = c(1,0,2), #this may be arima not Arima?
        seasonal=c(0,1,0),
        include.drift = TRUE)

Then when I use the forecast and sweep function I changed it (I guess) to date

#Forecast with Sweep Functions----

fcast_arima_tbl <- forecast(fit_arima2, h = nrow(test_tbl)) %>%
  sw_sweep(timetk_idx = TRUE, rename_index = "date") #sweep converts it to a DF

Let me go back in the code and see if I can fix that, I will let you know, UGH!

WHP

From: Rui Barradas <ruipbarradas using sapo.pt>
Sent: Saturday, June 15, 2019 3:51 PM
To: Bill Poling <Bill.Poling using zelis.com>; Richard M. Heiberger <rmh using temple.edu>
Cc: r-help (r-help using r-project.org) <r-help using r-project.org>
Subject: Re: [R] Help with a third ggplot error

Hello,

Inline.

Às 20:29 de 15/06/19, Bill Poling escreveu:
> Hello Richard, thank you for your response.
>
> Here is what I get with your suggestion, however, I am unsure of what I am looking at, perhaps you can interpret.
>
> I sure appreciate your help Sir!
>
> g4 <- fcast_arima_tbl1 %>%
> ggplot(aes(date, NetEditRev, color = key)) + #Now date due to sweep
> 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

Isn't column 'x' Date or Date2, with upper case 'D'?
You have date, a function:

R> date
function ()
.Internal(date())
<bytecode: 0x6c8a9b8>
<environment: namespace:base>


Hope this helps,

Rui Barradas



>
> 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
>
> #Call
> rlang::last_error()
> #to see a backtrace you will have to figure out which of your variables is not properly specified.
>
> 1. (function (x, ...) ...
> 2. ggplot2:::print.ggplot(x)
> 4. ggplot2:::ggplot_build.ggplot(x)
> 5. ggplot2:::by_layer(function(l, d) l$compute_aesthetics(d, plot)) 6.
> ggplot2:::f(l = layers[[i]], d = data[[i]]) 7. l$compute_aesthetics(d,
> plot) 8. ggplot2:::f(..., self = self) 9.
> ggplot2:::as_gg_data_frame(evaled)
> 12. tibble:::as_tibble.list(x)
> 13. tibble:::lst_to_tibble(x, .rows, .name_repair, col_lengths(x)) 14.
> tibble:::check_valid_cols(x)
>
> From: Richard M. Heiberger <mailto:rmh using temple.edu>
> Sent: Saturday, June 15, 2019 3:17 PM
> To: Bill Poling <mailto:Bill.Poling using zelis.com>
> Cc: r-help (mailto:r-help using r-project.org) <mailto:r-help using r-project.org>
> Subject: Re: [R] Help with a third ggplot error
>
> you did something like this:
>
>> mydf <- data.frame(y=1:16,
> + AA=rep(factor(letters[1:8]), 2),
> + BB=rep(factor(LETTERS[12:13]), each=8),
> + CC=rep(factor(rep(LETTERS[9:11], times=c(3,1,4))), 2))
>> ggplot(mydf, aes(ls, y))
> 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
> Call `rlang::last_error()` to see a backtrace
>>
>
> you will have to figure out which of your variables is not properly specified.
>
> Rich
>
> On Fri, Jun 14, 2019 at 3:30 PM Bill Poling <mailto:Bill.Poling using 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. This transmission may contain information which is privileged and confidential and is intended for the personal and confidential use of the named recipient only. Such information may be protected by applicable State and Federal laws from this disclosure or unauthorized use. If the reader of this message is not the intended recipient, or the employee or agent responsible for delivering the message to the intended recipient, you are hereby notified that any disclosure, review, discussion, copying, or taking any action in reliance on the contents of this transmission is strictly prohibited. If you have received this transmission in error, please contact the sender immediately. Zelis, 2018.


More information about the R-help mailing list