44# ' @rdname plotting_prep
55# '
66# ' @description
7- # ' Convert the output of [check_demography_alignment()] to a long-format tibble.
7+ # ' Transform burden estimate data from modelling groups to make them suitable
8+ # ' for plotting using an appropriate [plotting function][plotting]. Each
9+ # ' preparation function corresponds to a plotting function.
810# '
911# ' @param burden For `prep_plot_demography()`, a `<tibble>` output from
1012# ' [check_demography_alignment()].
11- # '
12- # ' For `prep_plot_age()`, ... ADD DETAILS.
13- # '
14- # ' For `prep_plot_burden_decades()`, ... ADD DETAILS.
15- # '
16- # ' For `prep_plot_global_burden()`, ... ADD DETAILS.
13+ # ' For other functions, a burden dataset similar to [eg_burden_template].
1714# '
1815# ' @return
1916# '
2017# ' - For `prep_plot_demography()`: a `<tibble>` in long-format, with the
2118# ' identifier-columns, "scenario", "age", and "year", with the added column
2219# ' "value_millions".
2320# '
24- # ' - For `prep_plot_age()`:
21+ # ' - For `prep_plot_age()`: a `<tibble>` with the columns "scenario",
22+ # ' "burden_outcome", "age", "value_millions".
23+ # '
24+ # ' - For `prep_plot_burden_decades()`: a `<tibble>` with the columns "scenario",
25+ # ' "burden_outcome", "decade_label", and "value_millions".
26+ # '
27+ # ' - For `prep_plot_global_burden()`: a nested `<tibble>` with the string
28+ # ' column "burden_outcome", and a list column of tibbles "burden_data".
29+ # '
30+ # ' - For `prep_plot_coverage_set()`: WIP
31+ # '
32+ # ' - For `prep_plot_fvp()`: WIP.
2533# '
2634# ' @export
2735prep_plot_demography <- function (burden ) {
@@ -86,16 +94,25 @@ prep_plot_demography <- function(burden) {
8694prep_plot_age <- function (burden ) {
8795 checkmate :: assert_tibble(burden )
8896
89- burden_summary <- dplyr :: summarise (
97+ burden_long <- tidyr :: pivot_longer (
9098 burden ,
99+ {{ burden_outcome_names }},
100+ names_to = " burden_outcome"
101+ )
102+
103+ burden_summary <- dplyr :: summarise(
104+ burden_long ,
91105 value_millions = sum(.data $ value ) / 1e6 ,
92- .groups = c(" scenario" , " burden_outcome" , " age" )
106+ .by = c(" scenario" , " burden_outcome" , " age" )
93107 )
94108
95109 burden_summary
96110}
97111
98112# ' @name plotting_prep
113+ # '
114+ # ' @param year_max The maximum year to be represented in a subsequent figure.
115+ # ' For `prep_plot_burden_decades()`, must be a decade, i.e., multiple of 10.
99116# '
100117# ' @export
101118prep_plot_burden_decades <- function (burden , year_max ) {
@@ -118,7 +135,7 @@ prep_plot_burden_decades <- function(burden, year_max) {
118135 burden_data ,
119136 year = pmin(
120137 .data $ year ,
121- .data $ year_max - 1
138+ year_max - 1
122139 ),
123140 decade = floor(.data $ year / 10 ) * 10 ,
124141 decade_label = dplyr :: if_else(
@@ -128,10 +145,16 @@ prep_plot_burden_decades <- function(burden, year_max) {
128145 )
129146 )
130147
148+ burden_data <- tidyr :: pivot_longer(
149+ burden_data ,
150+ {{ burden_outcome_names }},
151+ names_to = " burden_outcome"
152+ )
153+
131154 burden_data <- dplyr :: summarise(
132155 burden_data ,
133156 value_millions = sum(.data $ value ) / 1e6 ,
134- .groups = c(" scenario" , " burden_outcome" , " decade_label" )
157+ .by = c(" scenario" , " burden_outcome" , " decade_label" )
135158 )
136159
137160 burden_data
@@ -144,11 +167,19 @@ prep_plot_global_burden <- function(burden) {
144167 # TODO: add colnames check
145168 checkmate :: assert_tibble(burden )
146169
147- nesting_cols <- " outcome"
170+ nesting_cols <- " burden_outcome"
171+
172+ burden_long <- tidyr :: pivot_longer(
173+ burden ,
174+ {{ burden_outcome_names }},
175+ names_to = nesting_cols
176+ )
177+
178+ burden_long $ value_millions <- burden_long $ value / 1e6
148179
149180 # create a nested tibble with a list column named "burden_data"
150181 burden_nested <- tidyr :: nest(
151- burden ,
182+ burden_long ,
152183 .by = {{ nesting_cols }},
153184 .key = " burden_data"
154185 )
@@ -158,7 +189,7 @@ prep_plot_global_burden <- function(burden) {
158189
159190# ' @name plotting_prep
160191# '
161- # ' @param coverage
192+ # ' @param coverage WIP. Coverage data.
162193# '
163194# ' @export
164195prep_plot_coverage_set <- function (coverage ) {
@@ -203,11 +234,9 @@ prep_plot_coverage_set <- function(coverage) {
203234
204235# ' @name plotting_prep
205236# '
206- # ' @param fvp
207- # '
208- # ' @param year_min
237+ # ' @param fvp WIP. Data on counts of fully vaccinated persons.
209238# '
210- # ' @param year_max
239+ # ' @param year_min Minimum year.
211240# '
212241# ' @export
213242prep_plot_fvp <- function (fvp , year_min , year_max ) {
0 commit comments