tidyverts / feasts

Feature Extraction And Statistics for Time Series
https://feasts.tidyverts.org/
295 stars 23 forks source link

autolayer problem #78

Closed robjhyndman closed 5 years ago

robjhyndman commented 5 years ago

The two plots should both work as the data sets passed to autolayer have the required information. For some reason the non-existence of .model in the autolayer object causes a problem in the first one but not the second.

library(tidyverse)
library(tsibble)
#> 
#> Attaching package: 'tsibble'
#> The following object is masked from 'package:dplyr':
#> 
#>     id
library(fable)
#> Loading required package: fabletools
#> 
#> Attaching package: 'fabletools'
#> The following object is masked from 'package:stats':
#> 
#>     decompose

snowy <- tourism %>% 
  filter(
    Region == "Snowy Mountains",
    Purpose == "Holiday"
  )
fit <- snowy %>% model(ets = ETS(Trips))
sim <- fit %>% generate(h="3 years", times=10)

sim %>%
  autoplot(.sim) +
  autolayer(snowy, Trips) +
  guides(col=FALSE)
#> Error in interaction(Region, State, Purpose, .model, .rep, sep = "/"): object '.model' not found

sim %>%
  autoplot(.sim) +
  autolayer(tourism, Trips) +
  guides(col=FALSE)

Created on 2019-10-16 by the reprex package (v0.3.0)

mitchelloharawild commented 5 years ago

Interesting, first time I've noticed a use for inherit.aes for geoms. Issue is that autolayer() is inheriting the colour aesthetic from autoplot(), requiring .model (and .rep). When the autolayer() data has more than one key, it will overwrite the colour so nothing will be inherited from the autoplot(), allowing it to work.

Generally speaking, I think autoplot() for simulated values is a bad idea, as a better plot can be obtained by more carefully specifying the colour. Having a different colour for each replication is probably unnecessary.