facebook / prophet

Tool for producing high quality forecasts for time series data that has multiple seasonality with linear or non-linear growth.
https://facebook.github.io/prophet
MIT License
18.29k stars 4.51k forks source link

plot_forecast_component() fails to plot any `name` containing spaces #1696

Closed cmcrowley closed 3 years ago

cmcrowley commented 3 years ago

Most names of generated_holidays contain spaces, and so fail to plot when passed to plot_forecast_component(). The tidyeval approach is to forego using aes_() or aes_string() and instead use quasiquotation in aes.

This is the same issue as documented here. Here, Tidyverse creator Hadley Wickham responds to this issue by suggesting changing use of aes_string.

Reprex:

library(prophet)
df <- data.frame('ds' = seq.Date(from=as.Date('2015-07-01'),
                                 to=as.Date('2020-07-01'),
                                 by=1),
                 'y' = rnorm(1828))
m <- prophet()
m <- add_country_holidays(m, country_name = 'US')
m <- fit.prophet(m, df)
future <- make_future_dataframe(m, periods = 50)
forecast <- predict(m, future)
plot_forecast_component(m=m, fcst=forecast, name=m$train.holiday.names[1])
Error in parse(text = elt) : <text>:1:5: unexpected symbol
1: New Year
        ^

R Session Info:

> sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

Random number generation:
 RNG:     Mersenne-Twister 
 Normal:  Inversion 
 Sample:  Rounding 

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

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

other attached packages:
[1] prophet_0.6.1 rlang_0.4.6   Rcpp_1.0.5   

loaded via a namespace (and not attached):
 [1] pillar_1.4.4         compiler_3.6.0       prettyunits_1.1.1    tools_3.6.0          pkgbuild_1.0.8       gtable_0.3.0         jsonlite_1.7.0      
 [8] lifecycle_0.2.0      tibble_3.0.1         pkgconfig_2.0.3      cli_2.0.2            rstudioapi_0.11      parallel_3.6.0       curl_4.3            
[15] yaml_2.2.1           loo_2.3.1            gridExtra_2.3        extraDistr_1.9.1     withr_2.2.0          dplyr_1.0.0          generics_0.0.2      
[22] vctrs_0.3.1          grid_3.6.0           stats4_3.6.0         tidyselect_1.1.0     glue_1.4.1           inline_0.3.16        R6_2.4.1            
[29] processx_3.4.2       fansi_0.4.1          rstan_2.21.2         ggplot2_3.3.2        tidyr_1.1.0          callr_3.4.3          purrr_0.3.4         
[36] magrittr_1.5         matrixStats_0.56.0   scales_1.1.1         codetools_0.2-16     ps_1.3.3             ellipsis_0.3.1       StanHeaders_2.21.0-6
[43] assertthat_0.2.1     colorspace_1.4-1     V8_3.2.0             stringi_1.4.6        munsell_0.5.0        RcppParallel_5.0.2   crayon_1.3.4  
bletham commented 3 years ago

Thanks for raising this, and for the clean repro example and description of the issue/solution. This is definitely a bug, but it looks like will not be too hard to fix.

In the meantime, I think the only workaround would be to copy out the plotting code from https://github.com/facebook/prophet/blob/187bf06bf7d752ddaff7bcbe993c2b91f66e492f/R/R/plot.R#L177 and remove the lines that use aes_string.

bletham commented 3 years ago

The fix has been pushed to CRAN in the latest v1.0 release