[英]Why is the autoplot function giving an error in this example from publication "Forecasting: Principles and Practice" not working?
I am working through section 2.2 "Time Plots" of publication Forecasting: Principles and Practice by Hyndman and Athanasopoulos ( https://otexts.com/fpp3/time-plots.html ) and I can't get the autoplot()
function referenced therein to work.我正在研究 Hyndman 和 Athanasopoulos( https://otexts.com/fpp3/time-plots.html )的出版物预测的第 2.2 节“时间图”,我无法引用
autoplot()
function在其中工作。 I assume autoplot()
derives from the forecast package but as you can see in the below code I have also fiddled with ggplot2 and ggfortify packages and neither of these work either.我假设
autoplot()
源自预测 package 但正如您在下面的代码中看到的那样,我还摆弄了 ggplot2 和 ggfortify 包,但这些都不起作用。 The error I get when trying the forecast package is " Error in forecast::autoplot()
:. Objects of class <tbl_ts> are not supported by autoplot. "我在尝试预测 package 时遇到的错误是“
forecast::autoplot()
:. class <tbl_ts> 的对象不受自动绘图支持。 ”
Any ideas how to get this autoplot()
function working?任何想法如何让这个
autoplot()
function 工作?
Here's the publication's autoplot()
output that I'm trying to ape:这是我试图模仿的出版物的
autoplot()
output:
Code (in this example I was trying forecast package by using forecast::autoplot(...)
; further note that installing the tsibbledata package provides the "ansett" data used in this example):代码(在此示例中,我尝试使用
forecast::autoplot(...)
;进一步注意,安装 tsibbledata package 提供了此示例中使用的“ansett”数据):
library(dplyr)
library(tsibble)
library(tsibbledata)
library(forecast)
library(ggplot2)
library(ggfortify)
melsyd_economy <- ansett %>%
filter(Airports == "MEL-SYD", Class == "Economy") %>%
mutate(Passengers = Passengers/1000)
forecast::autoplot(melsyd_economy, Passengers) +
labs(title = "Ansett airlines economy class",
subtitle = "Melbourne-Sydney",
y = "Passengers ('000)")
The autoplot
method for tsibble
s is from the fabletools
package. SeePlot time series from a tsibble . autoplot
s 的fabletools
tsibble
请参阅Plot 时间序列 from a tsibble 。
library(dplyr)
library(ggplot2)
library(tsibbledata)
library(fabletools)
melsyd_economy <- ansett %>%
filter(Airports == "MEL-SYD", Class == "Economy") %>%
mutate(Passengers = Passengers / 1000)
autoplot(melsyd_economy, Passengers) +
labs(
title = "Ansett airlines economy class",
subtitle = "Melbourne-Sydney",
y = "Passengers ('000)"
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.