hubverse-org / hubVis

Plotting methods for hub model outputs
https://hubverse-org.github.io/hubVis/
Other
3 stars 0 forks source link

Point and interval forecasts are not clearly separated by forecast date when plotted #16

Open lshandross opened 9 months ago

lshandross commented 9 months ago

When forecasts made on multiple forecasts dates are plotted at the same time, all of the forecasts are connected even though they should not be and this is not desirable behavior. See the attached images at the bottom for the desired behavior (achievable using covidHubUtils::plot_forecasts()) vs the current behavior demonstrated by hubVis::plot_step_ahead_model_output.

This behavior is particularly noticeable when there is a large gap between forecast dates, like during the off season for flu forecasting from around June to the end of September, when there should be no plotted forecasts.

A simple, reproducible example is given below using the data in the attached zip file:

library(tidyverse)
library(lubridate)
library(hubUtils)
library(hubVis)

flu_truth_all <- readr::read_rds("flu_truth_all.rds")
flu_forecasts_baseline <- readr::read_rds("flu_baseline_hub.rds")
flu_dates_21_22 <- as.Date("2022-01-24") + weeks(0:21)
flu_dates_22_23 <- as.Date("2022-10-17") + weeks(0:30)
all_flu_dates <- c(flu_dates_21_22, flu_dates_22_23)

select_dates <- all_flu_dates[seq(1, 53, 4)]

baseline_ca <- flu_forecasts_baseline |> 
  dplyr::filter(location == "06", forecast_date %in% select_dates)

truth_ca <- flu_truth_all |> 
  dplyr::filter(location == "06")

plot_step_ahead_model_output(
  baseline_ca,
  truth_ca,
  use_median_as_point=TRUE,
  show_plot=TRUE,
  x_col_name="target_end_date",
  x_truth_col_name = "target_end_date",
  show_legend=FALSE,
  facet="model_id",
  facet_nrow=5,
  interactive=FALSE,
  fill_transparency = 0.45,
  intervals=c(0.5, 0.8, 0.95),
  title="Weekly Incident Hospitalizations for Influenza in California"
)

ca_forecasts_distinct ca_forecasts_connected

flu_baseline_truth.zip

LucieContamin commented 5 months ago

Issues partially done for "static" plot.

Still to do: