我有一个来自 Seasonal 包的矩阵输出,我过滤掉“预测”列,只留下时间(月份)和“lowerci”和“upperci”条目。这是通过以下方式完成的:
season13201101FL.forecast[,c('lowerci','upperci')]
数据样本:
lowerci upperci
Oct 2017 2415.8826 3083.332
Nov 2017 2217.2670 3238.572
Dec 2017 1976.0041 3181.648
Jan 2018 2048.9771 3577.373
Feb 2018 2046.3051 3834.099
这是“mts”类。我正在使用 highcharter 库来绘制我的价值观。series.keys
但是,即使我用来映射,它似乎也没有同时使用“lowerci”和“upperci”列:
hc <- highchart(type = "stock") %>%
hc_add_series(season13201101FL, id = "Original", name = "Original-FL") %>%
hc_add_series(season13201101FL.seasonalData, id = "Seasonally Adjusted-FL", name = "Seasonally Adjusted") %>%
hc_add_series(season13201101FL.forecast[,c('forecast')], id = "Forecast-FL") %>%
hc_add_series(season13201101FL.forecast[,c('lowerci','upperci')], id = "ForecastRange-FL", keys = c('x', 'low', 'high'), type = "arearange")
hc
生成的图表显示了原始的、经季节性调整的和预测系列,但显示的预测范围没有连接点的“线”,每个时间条目只有一个实际数据点。如何让 highcharter 看到这是一个arearange
系列?
要重现使用以下作为导入 CSV 作为theCSV
:
date count
2008.0027 45778
2008.0874 50460
2008.1667 62162
2008.2514 55999
2008.3333 51571
2008.418 45044
2008.5 46357
2008.5847 48498
2008.6694 45472
2008.7514 47161
2008.8361 41907
2008.918 39131
2009.0027 33810
2009.0877 34469
然后代码是:
library(shiny)
library(highcharter)
library(dplyr)
library(tidyr)
library(seasonal)
seasonData <- ts(theCSV[,-1], frequency = 12, start = c(2008,1));
seasonData.seas <- seas(seasonData);
seasonData.seasonalData <- final(seasonData.seas);
seasonData.forecast <- series(seasonData.seas, "forecast.forecasts");
seasonData.seasComp <- series(seasonData.seas, "seats.seasonal");
hc <- highchart(type = "stock") %>%
hc_add_series(seasonData, id = "Original", name = "Original-FL") %>%
hc_add_series(seasonData.seasonalData, id = "Seasonally Adjusted-FL", name = "Seasonally Adjusted") %>%
hc_add_series(seasonData.forecast[,c('forecast')], id = "Forecast-FL") %>%
hc_add_series(seasonData.forecast[,c('lowerci','upperci')], id = "ForecastRange-FL", keys = c('x', 'low', 'high'), type = "arearange")
hc;