Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: vimcheck
Title: Diagnostics for Vaccine Impact Modelling Consortium Burden and
Impact Estimates
Version: 0.0.6
Version: 0.0.7
Authors@R: c(
person("Pratik", "Gupte", , "p.gupte24@imperial.ac.uk", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-5294-7819")),
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# vimcheck 0.0.7

- Fixed `plot_impact()` to retain zero estimates in year and birth-cohort
trajectories instead of drawing a line across them. Inputs with no nonzero
estimates still raise an error.

# vimcheck 0.0.6

- Fixed `basic_burden_sanity()` to return failed-check messages instead of
Expand Down
4 changes: 2 additions & 2 deletions R/fn_plotting_impact.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@
data,
.data$country %in% country,
.data$burden_outcome == burden_type,
.data$impact != 0 # can this be safely written as impact > 0?
!is.na(.data$impact)
)

if (nrow(impact) > 0) {
if (any(impact$impact != 0)) {
if (view == "cohort") {
checkmate::assert_names(names(data), must.include = "birth_cohort")
x_var <- "birth_cohort"
Expand All @@ -93,9 +93,9 @@
) +
ggplot2::geom_ribbon(alpha = 0.3) +
ggplot2::geom_line(aes(colour = .data$short_name), linewidth = 0.5) +
ggplot2::geom_point(aes(colour = .data$short_name), size = 0.5) +

Check warning on line 96 in R/fn_plotting_impact.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/fn_plotting_impact.R,line=96,col=16,[namespace_linter] Don't use `::` to access geom_point, which is already imported from ggplot2.
theme_vimc() +
facet_wrap(ggplot2::vars(.data$country), scales = "free_y") +

Check warning on line 98 in R/fn_plotting_impact.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/fn_plotting_impact.R,line=98,col=27,[namespace_linter] Don't use `::` to access vars, which is already imported from ggplot2.
labs(
x = x_lab,
y = glue::glue("{burden_type} averted"),
Expand Down Expand Up @@ -252,7 +252,7 @@
geom_point(aes(colour = .data$vaccine_delivery), size = 0.5) +
scale_x_continuous(labels = scales::number_format(1, big.mark = "")) +
facet_wrap(
ggplot2::vars(.data$country),

Check warning on line 255 in R/fn_plotting_impact.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/fn_plotting_impact.R,line=255,col=16,[namespace_linter] Don't use `::` to access vars, which is already imported from ggplot2.
scales = "free_y"
) +
labs(
Expand Down
51 changes: 51 additions & 0 deletions tests/testthat/test-plot_impact.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,57 @@ test_that("Plotting impact works", {
)
})

test_that("Impact trajectories retain zero estimates in both views", {
impact_data <- data.frame(
country = "A",
year = 2020:2023,
birth_cohort = 2000:2003,
burden_outcome = "cases",
impact = c(10, 0, 10, NA),
short_name = "routine"
)

for (values in list(c(10, 0, 10, NA), c(-10, 0, 10, NA))) {
impact_data$impact <- values

for (view in c("year", "cohort")) {
p <- plot_impact(impact_data, "A", "cases", view)
expected_x <- if (view == "year") 2020:2022 else 2000:2002
expected_y <- values[1:3]

expect_equal(p$data$impact, expected_y)

layers <- ggplot2::ggplot_build(p)$data
for (layer in layers[2:3]) {
expect_equal(layer$x, expected_x)
expect_equal(layer$y, expected_y)
}
}
}
})

test_that("Impact plots still reject outcomes without nonzero estimates", {
impact_data <- data.frame(
country = "A",
year = 2020:2022,
birth_cohort = 2000:2002,
burden_outcome = c("cases", "cases", "deaths"),
impact = c(0, NA, 10),
short_name = "routine"
)

for (view in c("year", "cohort")) {
expect_error(
plot_impact(impact_data, "A", "cases", view),
"No estimates remaining in the data"
)
expect_error(
plot_impact(impact_data, "A", "dalys", view),
"No estimates remaining in the data"
)
}
})

test_that("Plotting coverage and FVPs works", {
p <- plot_coverage_fvps(eg_fvps_2, "AGO")
expect_list(p, "ggplot")
Expand Down
Loading