[英]How to vary line types when using the autoplot() function to help the colour-blind among us?
Running the code below plots actual data (black line) against 4-month forecasts for that data.运行下面的代码绘制实际数据(黑线)与该数据的 4 个月预测值。 However, the forecast lines are indistinguishable to me since I don't see colours.
然而,预测线对我来说是无法区分的,因为我看不到颜色。 How can the lines be distinguished from each other (with the actual (non-forecast) data line, the black line, made thicker than the others), either via dashed lines or the use of markers?
如何通过虚线或使用标记将这些线相互区分(实际(非预测)数据线,黑线比其他线粗)? In XLS I used dashed lines/markers to distinguish.
在 XLS 中我使用虚线/标记来区分。
I have fooled around with ggplot(...scale_l.netype_manual(values = c("TRUE" = "solid", "FALSE" = "dotted"))...)
with no luck.我一直在
ggplot(...scale_l.netype_manual(values = c("TRUE" = "solid", "FALSE" = "dotted"))...)
没有运气。
Code:代码:
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"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.