运行以下代码绘制实际数据(黑线)与该数据的4个月预测比较。然而,由于我看不到颜色,预测线对我来说是无法区分的。如何区分这些线(实际(非预测)数据线,黑线,比其它线粗),通过虚线或使用标记?在XLS中,我使用虚线/标记来区分。
我已经愚弄了ggplot(...scale_linetype_manual(values = c("TRUE" = "solid", "FALSE" = "dotted"))...)
没有运气。
代码:
library(feasts)
library(fable)
library(ggplot2)
library(tsibble)
tmp <- data.frame(
Month = c(1,2,3,4,5,6,7,8,9,10),
StateX = c(1527,1297,933,832,701,488,424,353,302,280)
) %>%
as_tsibble(index = Month)
tmpNext4 <- data.frame(
Month = c(11,12,13,14),
StateX = c(211,182,153,125)
) %>%
as_tsibble(index = Month)
# Fit the models to tmp dataframe:
fit <- tmp %>%
model(
Mean = MEAN(StateX),
`Naïve` = NAIVE(StateX),
Drift = NAIVE(StateX ~ drift())
)
# Produce forecasts for the next 4 months:
fcTmp <- fit %>%
forecast(new_data = tmpNext4)
# Plot the forecasts:
fcTmp %>%
autoplot(tmp, level = NULL) +
autolayer(tmpNext4, StateX, colour = "black") +
labs(y = "Units",
title = "Units reaching dead state X",
subtitle = "(Months 11 - 15)") +
guides(colour = guide_legend(title = "Forecast"))
1条答案
按热度按时间af7jpaap1#