|
| 1 | +--- |
| 2 | +title: "Using plotting and preparation functions" |
| 3 | +output: rmarkdown::html_vignette |
| 4 | +vignette: > |
| 5 | + %\VignetteIndexEntry{Using plotting and preparation functions} |
| 6 | + %\VignetteEngine{knitr::rmarkdown} |
| 7 | + %\VignetteEncoding{UTF-8} |
| 8 | +--- |
| 9 | + |
| 10 | +```{r, include = FALSE} |
| 11 | +knitr::opts_chunk$set( |
| 12 | + collapse = TRUE, |
| 13 | + comment = "#>" |
| 14 | +) |
| 15 | +``` |
| 16 | + |
| 17 | +This vignette shows how to use the plotting-preparation and plotting functions in _vimcheck_. |
| 18 | + |
| 19 | +Note that all data used here are placeholders. |
| 20 | + |
| 21 | +```{r setup} |
| 22 | +library(vimcheck) |
| 23 | +``` |
| 24 | + |
| 25 | +## Compare demography |
| 26 | + |
| 27 | +Users can check demographic alignment of burden data using `check_demography_alignment()`, then prepare it for plotting using `prep_plot_demography()`, and plot it using `plot_compare_demography()`. |
| 28 | + |
| 29 | +```{r comparing_demography} |
| 30 | +burden <- eg_burden_template |
| 31 | +
|
| 32 | +burden <- check_demography_alignment(burden, eg_wpp) |
| 33 | +burden <- prep_plot_demography(burden) |
| 34 | +
|
| 35 | +plot_compare_demography(burden, 1) |
| 36 | +``` |
| 37 | + |
| 38 | +## Examine age patterns |
| 39 | + |
| 40 | +Users can check age patterns in burden data using `prep_plot_age()` and plotting using `plot_age_patterns()`. |
| 41 | + |
| 42 | +Note that values are placeholders and you should expect to see real age-wise burden patterns look very different. |
| 43 | + |
| 44 | +```{r age_patterns} |
| 45 | +burden <- eg_burden_template |
| 46 | +burden <- prep_plot_age(burden) |
| 47 | +
|
| 48 | +# manually set values as template default is NA, prevents ggplot warnings |
| 49 | +burden$value_millions <- 1.0 |
| 50 | +
|
| 51 | +plot_age_patterns(burden, 1) |
| 52 | +``` |
| 53 | + |
| 54 | +## Global burden by decade |
| 55 | + |
| 56 | +Users can check the global burden in each decade for each scenario using `prep_plot_burden_decades()` and `plot_global_burden_decades()`. |
| 57 | + |
| 58 | +```{r global_burden_decades} |
| 59 | +burden <- eg_burden_template |
| 60 | +year_max <- 2100 |
| 61 | +burden <- prep_plot_burden_decades(burden, year_max) |
| 62 | +
|
| 63 | +# manually set values as template default is NA, prevents ggplot warnings |
| 64 | +burden$value_millions <- 1.0 |
| 65 | +
|
| 66 | +plot_global_burden_decades(burden, 1) |
| 67 | +``` |
| 68 | + |
| 69 | +## Global burden timeseries |
| 70 | + |
| 71 | +Users can check a timeseries of global burdens by scenario and age group. |
| 72 | +In contrast with the plotting scheme above, `prep_plot_global_burden()` converts the burden data to long-format and transforms the data tibble into a [nested-tibble](https://tidyr.tidyverse.org/articles/nest.html). |
| 73 | +This gives a tibble with as many rows as burden outcomes: cases, deaths, DALYs and YLLs, and a tibble giving the annual values by age for each burden outcome. |
| 74 | + |
| 75 | +The function `plot_global_burden()` is intended to be applied row-wise, taking the burden outcome name (e.g. "cases") and the burden outcome data to plot a timeseries with values by age. |
| 76 | + |
| 77 | +```{r global_burden_ts} |
| 78 | +burden <- eg_burden_template |
| 79 | +burden <- prep_plot_global_burden(burden) |
| 80 | +
|
| 81 | +# NOTE: expected use case is to loop over nested column DFs |
| 82 | +# set values to a dummy placeholder |
| 83 | +burden$burden_data[[1]]$value_millions <- 1 |
| 84 | +
|
| 85 | +plot_global_burden( |
| 86 | + burden$burden_data[[1]], |
| 87 | + burden$burden_outcome[[1]], |
| 88 | + 1 |
| 89 | +) |
| 90 | +``` |
0 commit comments