diff --git a/NAMESPACE b/NAMESPACE index 99986bd..e9bed21 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,7 +3,6 @@ export(correct_sero_misclass) export(correct_sero_misclass_p) export(ggplot_prevalence) -export(ggplot_prevalence_ii) export(rogan_gladen_estimator) export(rogan_gladen_stderr_unk) export(sample_posterior_r_mcmc_hyperR) diff --git a/R/serosurvey_viz.R b/R/serosurvey_viz.R index 15977ce..b4ed9cd 100644 --- a/R/serosurvey_viz.R +++ b/R/serosurvey_viz.R @@ -5,18 +5,17 @@ #' @describeIn ggplot_prevalence ggplot2 visualization of proportions #' #' @param data input tibble -#' @param category denominator level -#' @param outcome numerator variable +#' @param denominator_level - denominator values column +#' @param numerator - numerator variable name column #' @param proportion point estimate #' @param proportion_upp upper interval #' @param proportion_low lower interval -#' @param breaks_n number of breaks in axis +#' #param breaks_n number of breaks in axis #' #' @import skimr #' @import tidyverse #' #' @export ggplot_prevalence -#' @export ggplot_prevalence_ii #' #' @examples #' @@ -25,34 +24,14 @@ #' # https://avallecam.github.io/serosurvey/articles/howto-reprex.html #' -ggplot_prevalence <- function(data,category,outcome, - proportion,proportion_upp,proportion_low, - breaks_n=5) { - data %>% - ggplot(aes(x = {{category}}, - y = {{proportion}}, - color={{outcome}}, - group={{outcome}})) + - # geom_point(aes(size=proportion_cv),position = position_dodge(width = 0.5)) + - geom_point(position = position_dodge(width = 0.5)) + - geom_errorbar(aes(max={{proportion_upp}},min={{proportion_low}}), - position = position_dodge(width = 0.5)) + - scale_y_continuous(labels = scales::percent_format(accuracy = 1), - breaks = scales::pretty_breaks(n = {{breaks_n}})) + - # scale_size_continuous(labels = scales::percent_format()) + - theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) -} - -#' @describeIn ggplot_prevalence ggplot_prevalence with new arguments -#' @inheritParams ggplot_prevalence -#' @param denominator_level - denominator values column -#' @param numerator - numerator variable name column - -ggplot_prevalence_ii <- function(data, - denominator_level, - numerator, - proportion,proportion_upp,proportion_low, - breaks_n=5) { +ggplot_prevalence <- function(data, + denominator_level, + numerator, + proportion, + proportion_upp, + proportion_low#, + # breaks_n=5 + ) { data %>% ggplot(aes(x = {{denominator_level}}, y = {{proportion}}, @@ -61,9 +40,36 @@ ggplot_prevalence_ii <- function(data, # geom_point(aes(size=proportion_cv),position = position_dodge(width = 0.5)) + geom_point(position = position_dodge(width = 0.5)) + geom_errorbar(aes(max={{proportion_upp}},min={{proportion_low}}), - position = position_dodge(width = 0.5)) + - scale_y_continuous(labels = scales::percent_format(accuracy = 1), - breaks = scales::pretty_breaks(n = {{breaks_n}})) + - # scale_size_continuous(labels = scales::percent_format()) + - theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) + position = position_dodge(width = 0.5)) #+ + # scale_y_continuous(#labels = scales::percent_format(accuracy = 1), + # breaks = scales::pretty_breaks(n = {{breaks_n}})) #+ + # scale_size_continuous(labels = scales::percent_format()) + + # theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) } + + +#' #' #param category denominator level +#' #param outcome numerator variable +#' #export ggplot_prevalence_ii +#' ggplot_prevalence <- function(data,category,outcome, +#' proportion,proportion_upp,proportion_low, +#' breaks_n=5) { +#' data %>% +#' ggplot(aes(x = {{category}}, +#' y = {{proportion}}, +#' color={{outcome}}, +#' group={{outcome}})) + +#' # geom_point(aes(size=proportion_cv),position = position_dodge(width = 0.5)) + +#' geom_point(position = position_dodge(width = 0.5)) + +#' geom_errorbar(aes(max={{proportion_upp}},min={{proportion_low}}), +#' position = position_dodge(width = 0.5)) + +#' scale_y_continuous(labels = scales::percent_format(accuracy = 1), +#' breaks = scales::pretty_breaks(n = {{breaks_n}})) + +#' # scale_size_continuous(labels = scales::percent_format()) + +#' theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) +#' } +#' +#' #' describeIn ggplot_prevalence ggplot_prevalence with new arguments +#' #' inheritParams ggplot_prevalence +#' #' param denominator_level - denominator values column +#' #' param numerator - numerator variable name column diff --git a/man/ggplot_prevalence.Rd b/man/ggplot_prevalence.Rd index 51e8ed9..d876ca2 100644 --- a/man/ggplot_prevalence.Rd +++ b/man/ggplot_prevalence.Rd @@ -2,30 +2,14 @@ % Please edit documentation in R/serosurvey_viz.R \name{ggplot_prevalence} \alias{ggplot_prevalence} -\alias{ggplot_prevalence_ii} \title{Visualization of proportions} \usage{ -ggplot_prevalence(data, category, outcome, proportion, proportion_upp, - proportion_low, breaks_n = 5) - -ggplot_prevalence_ii(data, denominator_level, numerator, proportion, - proportion_upp, proportion_low, breaks_n = 5) +ggplot_prevalence(data, denominator_level, numerator, proportion, + proportion_upp, proportion_low) } \arguments{ \item{data}{input tibble} -\item{category}{denominator level} - -\item{outcome}{numerator variable} - -\item{proportion}{point estimate} - -\item{proportion_upp}{upper interval} - -\item{proportion_low}{lower interval} - -\item{breaks_n}{number of breaks in axis} - \item{denominator_level}{\itemize{ \item denominator values column }} @@ -33,6 +17,13 @@ ggplot_prevalence_ii(data, denominator_level, numerator, proportion, \item{numerator}{\itemize{ \item numerator variable name column }} + +\item{proportion}{point estimate} + +\item{proportion_upp}{upper interval} + +\item{proportion_low}{lower interval +#param breaks_n number of breaks in axis} } \description{ visualization of proportions @@ -40,8 +31,6 @@ visualization of proportions \section{Functions}{ \itemize{ \item \code{ggplot_prevalence}: ggplot2 visualization of proportions - -\item \code{ggplot_prevalence_ii}: ggplot_prevalence with new arguments }} \examples{ diff --git a/vignettes/howto-reprex.Rmd b/vignettes/howto-reprex.Rmd index 8d0492e..11401ef 100644 --- a/vignettes/howto-reprex.Rmd +++ b/vignettes/howto-reprex.Rmd @@ -453,13 +453,16 @@ outcome_01_adj_tbl %>% ```{r} outcome_01_adj_tbl %>% filter(str_detect(numerator,"outcome")) %>% - ggplot_prevalence_ii( + ggplot_prevalence( denominator_level = denominator_level, numerator = numerator, proportion = prop, proportion_upp = prop_upp, proportion_low = prop_low) + - theme(axis.text.x = element_text(angle = 0, vjust = 0, hjust=0)) + + # theme(axis.text.x = element_text(angle = 0, vjust = 0, hjust=0)) + + scale_y_continuous( + labels = scales::percent_format(accuracy = 1), + breaks = scales::pretty_breaks(n = 5)) + # coord_flip() + facet_wrap(denominator~.,scales = "free") + # facet_grid(denominator~.,scales = "free_y") + diff --git a/vignettes/intro.Rmd b/vignettes/intro.Rmd index f3b49d7..e79b34a 100644 --- a/vignettes/intro.Rmd +++ b/vignettes/intro.Rmd @@ -1,5 +1,5 @@ --- -title: "Workflow: How to use the serosurvey R package?" +title: "Introduction: serosurvey R package?" output: rmarkdown::html_vignette vignette: > %\VignetteEncoding{UTF-8} @@ -25,6 +25,9 @@ knitr::opts_chunk$set(fig.width=10, fig.height=4) options(tidyverse.quiet = TRUE) ``` +## Introduction + + ```{r setup} library(serosurvey) ``` @@ -92,3 +95,5 @@ Here are a list of publications with interesting approaches using R: and post-stratification to account for test uncertainty with unknown specificity and sensitivity. Here a [case-study](https://github.com/bob-carpenter/diagnostic-testing/blob/master/src/case-study/seroprevalence-meta-analysis.Rmd). + +## References