首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法自动绘制R中的数据帧时间序列

无法自动绘制R中的数据帧时间序列
EN

Stack Overflow用户
提问于 2022-11-21 23:48:37
回答 1查看 34关注 0票数 0

我正在尝试使用以下数据集来完成一个时间序列,预测未来两年按月收到的电话数量。

https://open.canada.ca/data/en/dataset/12d55393-2c84-4681-8c04-dc43775dbdfd/resource/62b40b15-a010-4fe7-8d56-d631802231be

我使用了业务司机和车辆服务队列(英文+法文)

数据包括3列:呼叫的业务线、日期(月和年)和处理的电话数量。

对于我的初步分析,我尝试使用autoplot函数,但遇到了一些问题。我试过以下代码。

代码语言:javascript
复制
# Load the forecasting package
library(fpp3)

# Load the Data
load(Book3)

# Declare time series data
Book3 <- ts( Book3, [,3], start = 2016,1, frequency = 12)

############################################
Preliminary analysis
############################################
#Time Plot
autoplot(Book3) + 
  ggtitle("Test plot") + 
  ylab("Calls Handled")

"Book3“是我的数据集的名称。然而,问题是,当我尝试运行它时,我会得到以下错误:

代码语言:javascript
复制
Error in `autoplot()`:
! Objects of type tbl_df/tbl/data.frame not supported by autoplot.
Run `rlang::last_error()` to see where the error occurred.

还可以使用以下内容重构数据集:

代码语言:javascript
复制
structure(list(`Queue Group/Line of Business` = c("Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)", 
"Driver and Vehicle Services queues (English + French)", "Driver and Vehicle Services queues (English + French)"
), DATE = c("2016-Jan", "2016-Feb", "2016-Mar", "2016-Apr", "2016-May", 
"2016-Jun", "2016-Jul", "2016-Aug", "2016-Sep", "2016-Oct", "2016-Nov", 
"2016-Dec", "2017-Jan", "2017-Feb", "2017-Mar", "2017-Apr", "2017-May", 
"2017-Jun", "2017-Jul", "2017-Aug", "2017-Sep", "2017-Oct", "2017-Nov", 
"2017-Dec", "2018-Jan", "2018-Feb", "2018-Mar", "2018-Apr", "2018-May", 
"2018-Jun", "2018-Jul", "2018-Aug", "2018-Sep", "2018-Oct", "2018-Nov", 
"2018-Dec", "2019-Jan", "2019-Feb", "2019-Mar", "2019-Apr", "2019-May", 
"2019-Jun", "2019-Jul", "2019-Aug", "2019-Sep", "2019-Oct", "2019-Nov", 
"2019-Dec", "2020-Jan", "2020-Feb", "2020-Mar", "2020-Apr", "2020-May", 
"2020-Jun", "2020-Jul", "2020-Aug", "2020-Sep", "2020-Oct", "2020-Nov", 
"2020-Dec", "2021-Jan", "2021-Feb", "2021-Mar", "2021-Apr", "2021-May", 
"2021-Jun", "2021-Jul", "2021-Aug", "2021-Sep"), `Calls Handled` = c(70660, 
61905, 63322, 68323, 72465, 67761, 64797, 77825, 71506, 71563, 
73651, 62384, 78243, 66130, 72600, 57756, 71920, 75819, 73144, 
82160, 70994, 73033, 66115, 53979, 71682, 57638, 66280, 56167, 
75368, 70826, 73149, 79144, 70100, 72516, 63654, 53070, 73814, 
57584, 66132, 63191, 72111, 63801, 68660, 67934, 57454, 56167, 
49349, 45312, 60766, 50218, 56790, 62748, 84383, 95169, 79610, 
70333, 80930, 75381, 77950, 78096, 73031, 60816, 89674, 74114, 
74114, 74717, 64373, 64202, 99922)), class = c("tbl_df", "tbl", 
"data.frame"), row.names = c(NA, -69L))
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-11-22 00:34:15

用于将第3列转换为时间序列的语法不正确。它应该是:

代码语言:javascript
复制
Book3 <- ts(Book3[,3], frequency = 12, start = c(2016, 1))

然后:

代码语言:javascript
复制
autoplot(Book3)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74526027

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档