This function is used internally by plot_tb_burden and plot_tb_burden_overview to prepare data for plotting.

prepare_df_plot(
  df = NULL,
  dict = NULL,
  metric = "e_inc_100k",
  conf = NULL,
  metric_label = NULL,
  countries = NULL,
  years = NULL,
  compare_to_region = FALSE,
  facet = NULL,
  annual_change = FALSE,
  trans = "identity",
  download_data = TRUE,
  save = TRUE,
  verbose = FALSE,
  ...
)

Arguments

df

Dataframe of TB burden data, as sourced by get_tb_burden. If not specified then will source the WHO TB burden data, either locally if available or directly from the WHO (if download_data = TRUE).

dict

A tibble of the data dictionary. See get_data_dict for details. If not supplied the function will attempt to load a saved version of the dictionary. If this fails and download_data = TRUE then the dictionary will be downloaded.

metric

Character string specifying the metric to plot

conf

Character vector specifying the name variations to use to specify the upper and lower confidence intervals. Defaults to NULL for which no confidence intervals are used. Used by annual_change.

metric_label

Character string specifying the metric label to use.

countries

A character string specifying the countries to target.

years

Numeric vector of years. Defaults to NULL which includes all years in the data.

compare_to_region

Logical, defaults to FALSE. If TRUE all countries that share a region with those listed in countries will be plotted. Note that this will override settings for facet, unless it is set to "country".

facet

Character string, the name of the variable to facet by.

annual_change

Logical, defaults to FALSE. If TRUE then the percentage annual change is computed for the specified metric.

trans

A character string specifying the transform to use on the specified metric. Defaults to no transform ("identity"). Other options include log scaling ("log") and log base 10 scaling ("log10"). For a complete list of options see ggplot2::continous_scale.

download_data

Logical, defaults to TRUE. If not found locally should the data be downloaded from the specified URL?

save

Logical, should the data be saved for reuse during the current R session. Defaults to TRUE. If TRUE then the data is saved to the temporary directory specified by tempdir.

verbose

Logical, defaults to FALSE. Should additional status and progress messages be displayed.

...

Additional arguments to pass to get_tb_burden.

Value

A list containing 3 elements, the dataframe to plot, the facet to use and the label to assign to the metric axis.

See also

plot_tb_burden plot_tb_burden_overview

Examples

prepare_df_plot(countries = "Guinea")
#> $df #> # A tibble: 19 x 73 #> country iso2 iso3 iso_numeric g_whoregion year e_pop_num e_inc_100k #> <fct> <chr> <chr> <int> <chr> <int> <int> <dbl> #> 1 Guinea GN GIN 324 Africa 2000 8240730 228 #> 2 Guinea GN GIN 324 Africa 2001 8417081 224 #> 3 Guinea GN GIN 324 Africa 2002 8586074 221 #> 4 Guinea GN GIN 324 Africa 2003 8753093 218 #> 5 Guinea GN GIN 324 Africa 2004 8925743 214 #> 6 Guinea GN GIN 324 Africa 2005 9109581 210 #> 7 Guinea GN GIN 324 Africa 2006 9307425 206 #> 8 Guinea GN GIN 324 Africa 2007 9518162 200 #> 9 Guinea GN GIN 324 Africa 2008 9738792 195 #> 10 Guinea GN GIN 324 Africa 2009 9964469 190 #> 11 Guinea GN GIN 324 Africa 2010 10192176 186 #> 12 Guinea GN GIN 324 Africa 2011 10420472 183 #> 13 Guinea GN GIN 324 Africa 2012 10652031 180 #> 14 Guinea GN GIN 324 Africa 2013 10892817 177 #> 15 Guinea GN GIN 324 Africa 2014 11150982 177 #> 16 Guinea GN GIN 324 Africa 2015 11432088 177 #> 17 Guinea GN GIN 324 Africa 2016 11738429 176 #> 18 Guinea GN GIN 324 Africa 2017 12067519 176 #> 19 Guinea GN GIN 324 Africa 2018 12414293 176 #> # … with 65 more variables: e_inc_100k_lo <dbl>, e_inc_100k_hi <dbl>, #> # e_inc_num <int>, e_inc_num_lo <int>, e_inc_num_hi <int>, #> # e_tbhiv_prct <dbl>, e_tbhiv_prct_lo <dbl>, e_tbhiv_prct_hi <dbl>, #> # e_inc_tbhiv_100k <dbl>, e_inc_tbhiv_100k_lo <dbl>, #> # e_inc_tbhiv_100k_hi <dbl>, e_inc_tbhiv_num <int>, e_inc_tbhiv_num_lo <int>, #> # e_inc_tbhiv_num_hi <int>, e_mort_exc_tbhiv_100k <dbl>, #> # e_mort_exc_tbhiv_100k_lo <dbl>, e_mort_exc_tbhiv_100k_hi <dbl>, #> # e_mort_exc_tbhiv_num <int>, e_mort_exc_tbhiv_num_lo <int>, #> # e_mort_exc_tbhiv_num_hi <int>, e_mort_tbhiv_100k <dbl>, #> # e_mort_tbhiv_100k_lo <dbl>, e_mort_tbhiv_100k_hi <dbl>, #> # e_mort_tbhiv_num <int>, e_mort_tbhiv_num_lo <int>, #> # e_mort_tbhiv_num_hi <int>, e_mort_100k <dbl>, e_mort_100k_lo <dbl>, #> # e_mort_100k_hi <dbl>, e_mort_num <int>, e_mort_num_lo <int>, #> # e_mort_num_hi <int>, cfr <dbl>, cfr_lo <dbl>, cfr_hi <dbl>, cfr_pct <int>, #> # cfr_pct_lo <int>, cfr_pct_hi <int>, c_newinc_100k <dbl>, c_cdr <dbl>, #> # c_cdr_lo <dbl>, c_cdr_hi <dbl>, source_rr_new <chr>, #> # source_drs_coverage_new <chr>, source_drs_year_new <int>, #> # e_rr_pct_new <dbl>, e_rr_pct_new_lo <dbl>, e_rr_pct_new_hi <dbl>, #> # e_mdr_pct_rr_new <int>, source_rr_ret <chr>, source_drs_coverage_ret <chr>, #> # source_drs_year_ret <int>, e_rr_pct_ret <dbl>, e_rr_pct_ret_lo <dbl>, #> # e_rr_pct_ret_hi <dbl>, e_mdr_pct_rr_ret <int>, e_inc_rr_num <int>, #> # e_inc_rr_num_lo <int>, e_inc_rr_num_hi <int>, e_mdr_pct_rr <dbl>, #> # e_rr_in_notified_labconf_pulm <int>, #> # e_rr_in_notified_labconf_pulm_lo <int>, #> # e_rr_in_notified_labconf_pulm_hi <int>, `Estimated incidence (all forms) #> # per 100 000 population` <dbl>, Year <int> #> #> $facet #> NULL #> #> $metric_label #> [1] "Estimated incidence (all forms) per 100 000 population" #>