Error: Objects of type ts not supported by autoplot. Cannot knit RMarkdown (packages `fpp2` vs `fpp3`)

1.4k views Asked by At

I have a small problem with Rob Hyndman's packages fpp2 and fpp3.

I have ts object

head(visitors)

[1] "ts"
      May   Jun   Jul   Aug   Sep   Oct
1985  75.7  75.4  83.1  82.9  77.3 105.7

Both packages fpp2 and fpp3 allow me to make a chart, using autoplot function.

autoplot(visitors)

But when I try to knit a RMarkdown report, I cannot do it, using fpp3 package.

Error: Objects of type ts not supported by autoplot.

I read several responses, answered by Hyndman (this and this), but still not sure where is my error. I do not use ggfortify.

My dput is

structure(c(75.7, 75.4, 83.1, 82.9, 77.3, 105.7, 121.9, 150, 
98, 118, 129.5, 110.6, 91.7, 94.8, 109.5, 105.1, 95, 130.3, 156.7, 
190.1, 139.7, 147.8, 145.2, 132.7, 120.7, 116.5, 142, 140.4, 
128, 165.7, 183.1, 222.8, 161.3, 180.4, 185.2, 160.5, 157.1, 
163.8, 203.3, 196.9, 179.6, 207.3, 208, 245.8, 168.9, 191.1, 
180, 160.1, 136.6, 142.7, 175.4, 161.4, 149.9, 174.1, 192.7, 
247.4, 176.2, 192.8, 189.1, 181.1, 149.9, 157.3, 185.3, 178.2, 
162.7, 190.6, 198.6, 253.1, 177.4, 190.6, 189.2, 168, 161.4, 
172.2, 208.3, 199.3, 197.4, 216, 223.9, 266.8, 196.1, 238.2, 
217.8, 203.8, 175.2, 176.9, 219.3, 199.1, 190, 229.3, 255, 302.4, 
242.8, 245.5, 257.9, 226.3, 213.4, 204.6, 244.6, 239.9, 224, 
267.2, 285.9, 344, 250.5, 304.3, 307.4, 255.1, 214.9, 230.9, 
282.5, 265.4, 254, 301.6, 311, 384, 303.8, 319.1, 313.5, 294.2, 
244.8, 261.4, 329.7, 304.9, 268.6, 320.7, 342.9, 422.3, 317.2, 
392.7, 365.6, 333.2, 261.5, 306.9, 358.2, 329.2, 309.2, 350.4, 
375.6, 465.2, 342.9, 408, 390.9, 325.9, 289.1, 308.2, 397.4, 
330.4, 330.9, 366.5, 379.5, 448.3, 346.2, 353.6, 338.6, 341.1, 
283.4, 304.2, 372.3, 323.7, 323.9, 354.8, 367.9, 457.6, 351, 
398.6, 389, 334.1, 298.1, 317.1, 388.5, 355.6, 353.1, 397, 416.7, 
460.8, 360.8, 434.6, 411.9, 405.6, 319.3, 347.9, 429, 372.9, 
403, 426.5, 459.9, 559.9, 416.6, 429.2, 428.7, 405.4, 330.2, 
370, 446.9, 384.6, 366.3, 378.5, 376.2, 523.2, 379.3, 437.2, 
446.5, 360.3, 329.9, 339.4, 418.2, 371.9, 358.6, 428.9, 437, 
534, 396.6, 427.5, 392.5, 321.5, 260.9, 308.3, 415.5, 362.2, 
385.6, 435.3, 473.3, 566.6, 420.2, 454.8, 432.3, 402.8, 341.3, 
367.3, 472, 405.8, 395.6, 449.9, 479.9, 593.1, 462.4, 501.6, 
504.7, 409.5), .Tsp = c(1985.33333333333, 2005.25, 12), class = "ts")
1

There are 1 answers

0
Rob Hyndman On BEST ANSWER

The fpp2 package depends on the forecast package which contains an autoplot() function that handles ts objects.

The fpp3 package depends on the feasts package which contains an autoplot() function that handles tsibble objects.

Since you have a ts object, you need the fpp2 or forecast package. Make sure you load it in the Rmd file (using library(forecast)) before you call autoplot().