Autolayer() deleted from ggplot2 and forecast package - alternatives?

Hey guys I am trying to validate my dataforecasts , both tabulary and grafically. Problem is that I cant find autolayer both in forecast or in ggplot2.

Here my code:

  Actuals_TS = ts(data_testing_monthly, start=c(2013, 02), end = c(2018,05), frequency = 12)
   plot.ts ( Actuals_TS,type ="l", main= testing[p], xlab = "BM", ylab = "Billings")
   forecast1 <- window (Actuals_TS, start = c(year,01), end =c(2017,11))
   
   fit1 <- meanf (forecast1,h=6)
   fit2 <- rwf (forecast1, h=6)
   fit3<- snaive (forecast1, h=6)
   fc_monthlyhwa<-forecast ( ets(forecast1, model ="AAA", damped =FALSE))
   fc_monthlyauto<- forecast (ets(forecast1, model ="ZZZ", damped =FALSE))
   
   autoplot(window(Actuals_TS, start= c(2014,01), xlab = "BM", ylab = "Billings")+

now to the essential part
neither

forecast::autolayer(fc_monthlyhwa, series="Holt Winters Additive", PI=FALSE) )

nor
ggplot2::autolayer(fc_monthlyhwa, series="Holt Winters Additive", PI=FALSE) )

and

autolayer(fc_monthlyhwa, series="Holt Winters Additive", PI=FALSE) )

does work.....
It shows the vollowing error message:
Error: 'autolayer' is not an exported object from 'namespace:forecast' or that it is not known.
Can anyone help me?

Best regards

Anna

Could you please turn this into a self-contained reprex (short for reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.

Right now the best way to install reprex is:

# install.packages("devtools")
devtools::install_github("tidyverse/reprex")

If you've never heard of a reprex before, you might want to start by reading the tidyverse.org help page. The reprex dos and don'ts are also useful.

What to do if you run into clipboard problems

If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.

reprex::reprex(input = "fruits_stringdist.R", outfile = "fruits_stringdist.md")

For pointers specific to the community site, check out the reprex FAQ, linked to below.

1 Like

Thanks @mara Mara. Problem is that the function autolayer is not in the two libraries anymore.
I do not think its a programming issue.

Here the seesionInfo()

R version 3.1.2 (2014-10-31)
Platform: i386-w64-mingw32/i386 (32-bit)

ocale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252    LC_MONETARY=German_Germany.1252
[4] LC_NUMERIC=C                    LC_TIME=German_Germany.1252    

attached base packages:
[1] parallel  tcltk     stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] tsintermittent_1.9 MAPA_1.9           doParallel_1.0.10  iterators_1.0.8    foreach_1.4.3     
 [6] readxl_0.1.1       openxlsx_3.0.0     stringr_0.6.2      tibble_1.0         purrr_0.2.1       
[11] readr_0.2.2        tidyr_0.4.1        ggplot2_2.1.0      dplyr_0.4.3        plyr_1.8.3        
[16] data.table_1.9.4   qcc_2.6            fpp_0.5            lmtest_0.9-33      expsmooth_2.3     
[21] fma_2.01           tseries_0.10-32    forecast_7.1       timeDate_3012.100  zoo_1.7-13        

loaded via a namespace (and not attached):
 [1] assertthat_0.1   chron_2.3-45     codetools_0.2-9  colorspace_1.2-4 DBI_0.3.1       
 [6] digest_0.6.8     fracdiff_1.4-2   grid_3.1.2       gtable_0.1.2     labeling_0.3    
[11] lattice_0.20-29  lazyeval_0.1.10  magrittr_1.5     MASS_7.3-35      munsell_0.4.2   
[16] nnet_7.3-8       quadprog_1.5-5   R6_2.0.1         Rcpp_0.12.4      reshape2_1.4.1  
[21] scales_0.4.0     tools_3.1.2
1 Like

If you install the latest version of ggplot2 from github:
https://github.com/tidyverse/ggplot2/blob/master/R/autolayer.r#L12

And, according to the latest forecast docs:

# S3 method for mforecast
autoplot(object, PI = TRUE, facets = TRUE,
  colour = FALSE, ...)

# S3 method for mforecast
autolayer(object, series = NULL, PI = TRUE, ...)

# S3 method for mforecast
plot(x, main = paste("Forecasts from", unique(x$method)),
  xlab = "time", ...)

Here is a reprex. ggplot2::autolayer() errors out because I didn't put anything in it, but you can see it's there based on the error message it throws.

suppressPackageStartupMessages(library(tidyverse))
ggplot2::autolayer()
#> Error in paste(class(object), collapse = "/"): argument "object" is missing, with no default

library(forecast)
#> Warning: package 'forecast' was built under R version 3.4.4
#> 
#> Attaching package: 'forecast'
#> The following object is masked from 'package:ggplot2':
#> 
#>     autolayer
WWWusage %>% ets %>% forecast(h=20) -> fc
autoplot(WWWusage, series="Data") + 
  autolayer(fc, series="Forecast") + 
  autolayer(fitted(fc), series="Fitted")

Created on 2018-06-05 by the reprex package (v0.2.0).

1 Like

Thanks a lot. I am sorry for having one last question here:

devtools::install_github ("tidyverse/ggplot2")
Downloading GitHub repo tidyverse/ggplot2@master
from URL https://api.github.com/repos/tidyverse/ggplot2/zipball/master
Error in curl::curl_fetch_memory(url, handle = handle) : 
  Couldn't connect to server

I have tried downloading the ggplot2 but my computer does not seem to have the capacity right? Do you now a function to gain more memory /or a different solution to my problem?

EDIT: I am on a business computer I cannot access any firewall settings unfortunately...

It looks like a connection issue, but I could be wrong. Oh — that, or the space between devtools::install_github and the ("tidyverse/ggplot2") is throwing things. Otherwise you could try to download and install locally:
https://stat.ethz.ch/R-manual/R-devel/library/utils/html/install.packages.html

1 Like

Last thing - thanks so much you were helping a lot by the way :grin::
Since I ve installed now two ggplot2s. How can I suppress the old version of the ggplot2, so I only use the newest one?

EDIT: I installed it and the autolayer still wont show in the package although it is in the zip Folder .... i am actually out of options now right?

Are you sure you have the right version loaded? Could you try making a reprex? It'll be much easier to see what's gone wrong if you do (even if it's showing an error).

I talked to my supervisor and due to coprporate confidentiallity I am not allowed to use reprex. I am sorry.
Basically I have loaded the following libraries:


options(java.parameters = "-Xmx8000m") # Allow Java to use more RAM, necessary for writing xlsx
library(readxl) # necessary to read data
library(forecast) # necessary to use forecasting methods
library(doParallel) # necessary to allow the use of multiple cores
library(tsintermittent) # TSB (Teunter-Syntetos-Babai) method
library (ggplot2)

Additionally I ve got issues loading the JVM (Error -6) for the Java environment:
This is my code:

year=2014

data_example_monthly<- as.data.frame (data_example_monthly)
data_example_monthly[is.na (data_example_monthly)]<-0

for (p in 1: length (testing)){

data_testing_monthly = data_example_monthly[data_example_monthly$RFP.Name==testing[p],-c(1,2)]

Actuals_TS = ts(data_testing_monthly, start=c(2013, 02), end = c(2018,05), frequency = 12)
plot.ts ( Actuals_TS,type ="l", main= testing[p], xlab = "BM", ylab = "Billings")
Actuals_TS%>% tsclean() %>%plot()

forecast1 <- window (Actuals_TS, start = c(year,01), end =c(2017,11))

fit1 <- meanf (forecast1,h=6)
fit2 <- rwf (forecast1, h=6)
fit3<- snaive (forecast1, h=6)
fc_monthlyhwa<-forecast ( ets(forecast1, model ="AAA", damped =FALSE), h=6)
fc_monthlyauto<- forecast (ets(forecast1, model ="ZZZ", damped =FALSE), h=6)

autoplot(window(Actuals_TS, start=c(2017,12), end=c(2018,05))+
autolayer(fit1, series="Mean", PI=FALSE))

autoplot(fit2)
autoplot(fit3)
autoplot(fc_monthlyhwa)
autoplot(fc_monthlyauto)

test <- window(Actuals_TS, start=c(2017,12), end=c(2018,05))
accuracy(fit1, test)
accuracy(fit2, test)
accuracy(fit3, test)
accuracy(fc_monthlyhwa, test)
accuracy(fc_monthlyauto, test)

}

and the sessionInfo = the one above
I am working on a 32 Bit / 4GB Laptop / Windows 7.
Do you have alternatives. Can I reproduce autolayer with lines?

Did you try updating the libraries? I have no clue when it comes to Java, but as I mentioned above, autolayer() definitely exists…

2 Likes

Thank you for helping me!
I found the issue; It was the firewall it was blocking the updates. I switched to my personal computer. I will go to IT to solve the issue.

2 Likes