Skip to content

Commit c9d1ab0

Browse files
Add vignette showing plotting
1 parent 0b70dfe commit c9d1ab0

4 files changed

Lines changed: 93 additions & 6 deletions

File tree

R/plotting.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ plot_age_patterns <- function(burden_age, fig_number) {
141141
scales = "free_y",
142142
labeller = labeller(scenario = label_wrap_gen(10))
143143
) +
144-
# TODO: check if needed if max age comes from data
145144
ggplot2::coord_cartesian(xlim = c(NA_real_, max_age)) +
146145
labs(
147146
y = "people (in millions)",
@@ -186,7 +185,7 @@ plot_global_burden_decades <- function(burden_decades, fig_number) {
186185
#'
187186
#' @param burden_data This is expected to be a `<tibble>` from a
188187
#' nested-`<tibble>` constructed using [prep_plot_global_burden()].
189-
#'
188+
#'
190189
#' @param outcome_name A string for an outcome name. Allowed outcome names are
191190
#' given in the package constant [constants][burden_outcome_names].
192191
#'

R/plotting_prep.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,12 @@ prep_plot_age <- function(burden) {
110110
}
111111

112112
#' @name plotting_prep
113-
#'
113+
#'
114114
#' @param year_max The maximum year to be represented in a subsequent figure.
115115
#' For `prep_plot_burden_decades()`, must be a decade, i.e., multiple of 10.
116116
#'
117117
#' @export
118118
prep_plot_burden_decades <- function(burden, year_max) {
119-
# TODO: add colnames check
120-
# TODO: general: make validator for burden data
121119
checkmate::assert_tibble(burden)
122120

123121
is_decade <- year_max %% 10 == 0

tests/testthat/test-plotting.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ test_that("plot_global_burden_decades() works", {
4040
vdiffr::expect_doppelganger("plot_global_burden_decades", p)
4141
})
4242

43-
test_that("plot_global_burden_decades() works", {
43+
test_that("plot_global_burden() works", {
4444
burden <- eg_burden_template
4545
burden <- prep_plot_global_burden(burden)
4646

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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

Comments
 (0)