Title: | Rt Visualization in D3 |
---|---|
Description: | Create interactive visualisations of Rt estimates using 'D3.js' (Gibbs et al. (2020) <doi:10.5281/zenodo.4011842>). Developed primarily targeting Rt estimates generated by the 'EpiNow2' package, 'RtD3' aims to make simple, beautiful visualisations that help researchers explore their results and share them with others. |
Authors: | Hamish Gibbs [aut, cre] |
Maintainer: | Hamish Gibbs <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.1 |
Built: | 2024-08-16 02:44:50 UTC |
Source: | https://github.com/epiforecasts/RtD3 |
Create a default reference for a input datasets. Also useful as a template when defining your own.
default_data_ref()
default_data_ref()
Create a default reference for a map legend. Also useful as a template when defining your own.
default_map_legend_ref()
default_map_legend_ref()
Create a default reference for time series colors. Also useful as a template when defining your own.
default_ts_color_ref()
default_ts_color_ref()
Define default colors for time series plots
Can be overridden with a list of the same format
default_ts_colors()
default_ts_colors()
Get Subregional Estimate Urls
getSubregionalUrls(path, areas)
getSubregionalUrls(path, areas)
path |
A character string container the overall path to subnational estimates |
areas |
A character vector listing the subregional estimates (assuming that listed in the geoData with capitalisation and without capitalisation in the path). |
A named list of subnational urls.
getSubregionalUrls(path = "https://epiforecasts.io/covid/posts/national/", areas = c('Afghanistan', 'Brazil', 'Colombia', 'United States'))
getSubregionalUrls(path = "https://epiforecasts.io/covid/posts/national/", areas = c('Afghanistan', 'Brazil', 'Colombia', 'United States'))
Joins two nested lists in the format required by summaryWidget
. This may
be useful for merging estimates from disparate data sources or linking national level estimates
with subnational estimates
joinRtData(rtData, rtData2)
joinRtData(rtData, rtData2)
rtData |
A nested list as required by |
rtData2 |
A nested list as required by |
A nested list as required by summaryWidget
base_url <- "https://raw.githubusercontent.com/epiforecasts/covid-rt-estimates/master/" subnational <- national <- list("Cases" = readInEpiNow2( path = paste0(base_url, "subnational/italy/cases/summary"), region_var = "region")) national <- list("Cases" = readInEpiNow2( path = paste0(base_url, "national/cases/summary"), region_var = "country"), regions = "Italy") out <- list() out$Cases <- joinRtData(subnational$Cases, national$Cases)
base_url <- "https://raw.githubusercontent.com/epiforecasts/covid-rt-estimates/master/" subnational <- national <- list("Cases" = readInEpiNow2( path = paste0(base_url, "subnational/italy/cases/summary"), region_var = "region")) national <- list("Cases" = readInEpiNow2( path = paste0(base_url, "national/cases/summary"), region_var = "country"), regions = "Italy") out <- list() out$Cases <- joinRtData(subnational$Cases, national$Cases)
Create a qualitative legend.
legend_qualitative(variable_name, legend_values)
legend_qualitative(variable_name, legend_values)
variable_name |
string, name of the variable of this legend. |
legend_values |
list, reference for legend colors in the format: 'value':'color', .... |
Create a qualitative legend. 'legend_scaleā accepts scales listed in d3-scale.
legend_sequential( variable_name, legend_scale = "scaleLinear", color_low = "white", color_high = "green", color_no_data = "lightgrey" )
legend_sequential( variable_name, legend_scale = "scaleLinear", color_low = "white", color_high = "green", color_no_data = "lightgrey" )
variable_name |
string, name of the variable of this legend. |
legend_scale |
string, type of legend scale, must be the name of a d3 scale. Default: "scaleLinear". |
color_low |
string, color for the lowest value of the legend. |
color_high |
string, color for the highest value of the legend. |
color_no_data |
string, color for no data entries. |
Reads in results from EpiNow2
and converts them into the RtD3
format. Supports
either input via a list object or from a file path/url.
readInEpiNow2(input_list, path, region_var = "region", regions)
readInEpiNow2(input_list, path, region_var = "region", regions)
input_list |
A list of results as returned by |
path |
A character string indicating the path (either file or URL) to the summary results |
region_var |
A character string that identifies the region name used. |
regions |
A character string indicating the regions of interest to returns. Defaults to all regions. |
A named list in the format required by summaryWidget
along with a summary table.
# Read in each summary folder base_path <- "https://raw.githubusercontent.com/epiforecasts/covid-rt-estimates/" rtData <- readInEpiNow2( path = paste0(base_path, "master/national/cases/summary"), region_var = "country") rtData france <- readInEpiNow2( path = paste0(base_path, "master/national/cases/summary"), region_var = "country", regions = "France") france
# Read in each summary folder base_path <- "https://raw.githubusercontent.com/epiforecasts/covid-rt-estimates/" rtData <- readInEpiNow2( path = paste0(base_path, "master/national/cases/summary"), region_var = "country") rtData france <- readInEpiNow2( path = paste0(base_path, "master/national/cases/summary"), region_var = "country", regions = "France") france
Create an Rt visualisation using D3. Need convenience functions to define defaults
summaryWidget( geoData = NULL, rtData = NULL, data_ref = NULL, subregional_ref = NULL, ts_color_ref = NULL, ts_bar_color = "lightgrey", projection = "geoEquirectangular", map_legend_ref = NULL, credible_threshold = 10, width = NULL, activeArea = "United Kingdom", downloadUrl = NULL, dryRun = FALSE )
summaryWidget( geoData = NULL, rtData = NULL, data_ref = NULL, subregional_ref = NULL, ts_color_ref = NULL, ts_bar_color = "lightgrey", projection = "geoEquirectangular", map_legend_ref = NULL, credible_threshold = 10, width = NULL, activeArea = "United Kingdom", downloadUrl = NULL, dryRun = FALSE )
geoData |
sf object, map data |
rtData |
data.frame, rt estimates in the format 'Source':'rtData':x, 'casesInfectionData':x, 'casesReportData':x, 'obsCasesData':x, ... |
data_ref |
list, reference for input data column names. Specify the column holding geometry to be symbolized 'rtData':'geometry_name':'region', ... |
subregional_ref |
list, reference to subnational estimates in the format 'country_name':'url', .... |
ts_color_ref |
list, reference for colors for time series plots. |
ts_bar_color |
string, color of observed cases bars in time series plots. |
projection |
string, map projection, must be named in d3-geo-projection. |
map_legend_ref |
list, reference for map legend variables |
credible_threshold |
integer, Threshold for credible intervals, maximum observed cases * this value will be removed. |
width |
integer, Width of widget in pixels. |
activeArea |
string, Area to symbolize first. |
downloadUrl |
string, URL to download data. |
dryRun |
Logical, defaults to FALSE. Should the function be tested without the widget being created. Useful for checking the integrity of input data. |
Output and render functions for using summaryWidget within Shiny applications and interactive Rmd documents.
summaryWidgetOutput(outputId, width = "100%", height = "400px") rendersummaryWidget(expr, env = parent.frame(), quoted = FALSE)
summaryWidgetOutput(outputId, width = "100%", height = "400px") rendersummaryWidget(expr, env = parent.frame(), quoted = FALSE)
outputId |
output variable to read from |
width , height
|
Must be a valid CSS unit (like |
expr |
An expression that generates a RtD3 |
env |
The environment in which to evaluate |
quoted |
Is |