Skip to content

Commit e13e0fa

Browse files
Update fn ops and docs
1 parent 1c10efb commit e13e0fa

7 files changed

Lines changed: 76 additions & 33 deletions

File tree

R/example_data.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#' \item{deaths}{Deaths averted}.
3737
#' \item{yll}{Years of life-loss averted}.
3838
#' \item{cohort_size}{Population size of the country in a year}.
39-
#' \itme{scenario}{Vaccination scenario.}
39+
#' \item{scenario}{Vaccination scenario.}
4040
#' }
4141
#'
4242
#' @keywords data

R/plotting.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ plot_global_burden_decades <- function(burden_decades, fig_number) {
186186
#'
187187
#' @param burden_data This is expected to be a `<tibble>` from a
188188
#' nested-`<tibble>` constructed using [prep_plot_global_burden()].
189+
#'
190+
#' @param outcome_name A string for an outcome name. Allowed outcome names are
191+
#' given in the package constant [constants][burden_outcome_names].
189192
#'
190193
#' @export
191194
plot_global_burden <- function(burden_data, outcome_name, fig_number) {

R/plotting_prep.R

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,32 @@
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
2735
prep_plot_demography <- function(burden) {
@@ -86,16 +94,25 @@ prep_plot_demography <- function(burden) {
8694
prep_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
101118
prep_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
164195
prep_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
213242
prep_plot_fvp <- function(fvp, year_min, year_max) {

inst/WORDLIST

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ BMC
22
Codecov
33
DALYs
44
Echeverria
5+
FVPs
56
GHA
67
Hallett
78
Jaspreet
@@ -16,5 +17,7 @@ VIMC
1617
WIP
1718
WPP
1819
autogenerated
20+
ggplot
1921
pkgdown
2022
tibble
23+
tibbles

man/eg_burden_template.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/plotting.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/plotting_prep.Rd

Lines changed: 17 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)