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

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

我对 Rob Hyndman 的 软件包 fpp2fpp3.

有一个小问题

我有ts个对象

head(visitors)

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

fpp2fpp3 都允许我使用 autoplot 函数制作图表。

autoplot(visitors)

但是当我尝试编写 RMarkdown 报告时,我无法使用 fpp3 包。

错误:autoplot 不支持 ts 类型的对象。

我读了几个回复,由 Hyndman (this and this) 回答,但仍然不确定我的错误在哪里。我不使用 ggfortify.

我的dput

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")

fpp2 包依赖于 forecast 包,后者包含处理 ts 对象的 autoplot() 函数。

fpp3 包依赖于 feasts 包,后者包含处理 tsibble 对象的 autoplot() 函数。

由于您有一个 ts 对象,您需要 fpp2forecast 包。确保在调用 autoplot().

之前将其加载到 Rmd 文件中(使用 library(forecast)