Overview

RtD3 creates interactive visualizations of rt estimates using JavaScript and D3. RtD3 provides an interface to these JavaScript visualizations from R. Plots can be added to the RStudio Viewer, included in R Markdown documents, or embedded in a Shiny app.

This package is closely linked to the estimates produced by the EpiNow2 package, an open source resource for creating rt estimates.

Basic visualization

RtD3 is flexible, and will attempt to generate an interactive visualization with whatever data sets it receives. Columns must be in a standard format (detailed in the documentation).

This example relies on estimates from epiforecasts covid-rt-estimates.

base_url <- 'https://raw.githubusercontent.com/epiforecasts/covid-rt-estimates/master/national/'

geoData <- rnaturalearth::ne_countries(returnclass = 'sf')

rtData <- list("Cases" = RtD3::readInEpiNow2(
  path = "https://raw.githubusercontent.com/epiforecasts/covid-rt-estimates/master/national/cases/summary",
  region_var = "country"
  ))

# Extract summary data from cases
summaryData <- rtData$Cases$summary

## Drop remaining summary data
rtData <- lapply(rtData, function(.){.[-1]})

Rt data is passed to the visualization function in a JSON-like list of lists to allow for visualization of different data training data sources. Rt data should be prepared in the format {'Source':{'rtData':x, 'casesInfectionData':x, 'casesReportData':x, 'obsCasesData':x}, ...}. All required datasets are then passed to the visualization function. Note: missing datasets in rtData should be NULL, not absent.

RtD3::summaryWidget(
  geoData = geoData,
  summaryData = summaryData,
  rtData = rtData,
)
## Warning in name_warning_geoData(name_diff): The following names are present
## in the estimates but not in the GeoData: Andorra, Antigua & Barbuda, Aruba,
## Bahamas, Bahrain ... and 32 more.

Notice the warning that some names in the estimates are not present in the geoData. Estimates for these areas will still be accessible using the dropdown. The disagreement between geographic names can be addressed before calling RtD3::summaryWidget.