当最后一个时间单位只有1个观测值时,R forecast中的GGR季节图不显示预测

当最后一个时间单位只有1个观测值时,R forecast中的GGR季节图不显示预测,r,ggplot2,time-series,forecasting,R,Ggplot2,Time Series,Forecasting,当使用for forecast软件包中的GG季节图时,如果每单位时间有2个或更多观测值(即一年中有2个以上季度),它将按需要工作 比如说 austres %>% ggseasonplot() yeilds 然而,如果我们去掉Q2-1993(我们最后一次观察是Q1-1993),我们会在图例上看到1993,但在情节上看不到。它应该作为一个点出现吗?如果是的话,我该如何把它放进去 austres %>% window(end=c(1993,1)) %>% ggseasonplo

当使用for forecast软件包中的GG季节图时,如果每单位时间有2个或更多观测值(即一年中有2个以上季度),它将按需要工作

比如说

austres  %>% ggseasonplot()
yeilds

然而,如果我们去掉Q2-1993(我们最后一次观察是Q1-1993),我们会在图例上看到1993,但在情节上看不到。它应该作为一个点出现吗?如果是的话,我该如何把它放进去

austres %>% window(end=c(1993,1)) %>% ggseasonplot()
我已经找到了一种方法——但我不知道是否是 最简单的方法

我在中修改了代码

tspx%窗口(end=c(1993,1)))
s
tspx <- tsp(austres %>% window(end=c(1993,1)))
s <- round(frequency(x))
x <- ts(austres, start = tspx[1], frequency = s)

data <- data.frame(
  y = as.numeric(x),
  year = trunc(time(x)),
  cycle = as.numeric(cycle(x)),
  time = as.numeric((cycle(x) - 1) / s)
)

austres %>% window(end=c(1993,1)) %>% ggseasonplot()+
  layer(
    data[nrow(data)-1,] ,
    geom = "point",
    stat = "identity",
    position = "identity", aes(x= time,y=y,col="1993")
  )