R语言 当使用autoplot()函数时,如何改变线条类型来帮助我们中的色盲?

vuktfyat  于 2023-01-28  发布在  其他
关注(0)|答案(1)|浏览(309)

运行以下代码绘制实际数据(黑线)与该数据的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"))
af7jpaap

af7jpaap1#

fcTmp %>%
  ggplot(aes(Month, .mean)) +
  geom_line(aes(linetype = .model, color = .model)) +
  geom_line(aes(y = StateX, linetype = "Next4", color = "Next4"), data = tmpNext4) +
  geom_line(aes(y = StateX), data = tmp)

相关问题