diff --git a/R/autoplot.summary.seroincidence.by.bar.R b/R/autoplot.summary.seroincidence.by.bar.R new file mode 100644 index 000000000..c871abac9 --- /dev/null +++ b/R/autoplot.summary.seroincidence.by.bar.R @@ -0,0 +1,29 @@ +#' Create bar plot for stratified seroincidence results +#' +#' +#' @return a [ggplot2::ggplot()] object + +autoplot.seroincidence.by.bar <- function(est_country_agedf, ageCat, incidence.rate, Country, CI.lwr, CI.upr, country_pal) { + ggplot(est_country_agedf, + aes( + y = fct_rev(ageCat), + x = incidence.rate * 1000, #rescale incidence + fill = Country + )) + + geom_bar(stat = "identity", + position = position_dodge2(reverse = TRUE), + show.legend = TRUE) + + geom_errorbar( + aes(xmin = CI.lwr * 1000, xmax = CI.upr * 1000), #rescale CIs + position = position_dodge2(reverse = TRUE) + ) + + labs(title = "Enteric Fever Seroincidence by Country and Age", + x = "Seroincidence rate per 1000 person-years", + y = "Age Category", + fill = "Country") + + theme_linedraw() + + theme(axis.text.y = element_text(size = 11), + axis.text.x = element_text(size = 11)) + + scale_x_continuous(expand = c(0, 10)) + + scale_fill_manual(values = country_pal) +} diff --git a/vignettes/articles/enteric_fever_example.Rmd b/vignettes/articles/enteric_fever_example.Rmd index 057735bd5..4b07244dd 100644 --- a/vignettes/articles/enteric_fever_example.Rmd +++ b/vignettes/articles/enteric_fever_example.Rmd @@ -7,9 +7,11 @@ output: toc: true vignette: > %\VignetteIndexEntry{Enteric Fever Seroincidence Vignette} - %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} + %\VignetteEngine{knitr::rmarkdown} bibliography: ../references.bib +editor_options: + chunk_output_type: console --- ## Introduction @@ -154,9 +156,9 @@ We see that across countries, our data is highly skewed with the majority of res xs_data %>% mutate(Country = fct_relevel(Country, "Bangladesh", "Pakistan", "Nepal")) %>% - autoplot(strata = "Country", type = "density") + + autoplot(strata = "Country", type = "density", log = TRUE) + scale_fill_manual(values = country_pal) + - scale_x_log10(labels = scales::label_comma()) + labs(x = "Log Antibody Response Value") ``` @@ -281,15 +283,14 @@ ggplot(est_country_agedf, fill = Country )) + geom_bar(stat = "identity", - position = position_dodge(), + position = position_dodge2(reverse = TRUE), show.legend = TRUE) + geom_errorbar( aes(xmin = CI.lwr * 1000, xmax = CI.upr * 1000), #rescale CIs - position = position_dodge(width = 0.9), - width = .2 + position = position_dodge2(reverse = TRUE) ) + labs(title = "Enteric Fever Seroincidence by Country and Age", - x = "Seroincidence rate per 1000 person-years", + x = "Seroconversion rate per 1000 person-years", y = "Age Category", fill = "Country") + theme_linedraw() +