Skip to content

Commit

Permalink
update viz function
Browse files Browse the repository at this point in the history
  • Loading branch information
avallecam committed Oct 20, 2020
1 parent 36922bb commit 19ba2e0
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 61 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
80 changes: 43 additions & 37 deletions R/serosurvey_viz.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
#'
Expand All @@ -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}},
Expand All @@ -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
29 changes: 9 additions & 20 deletions man/ggplot_prevalence.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions vignettes/howto-reprex.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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") +
Expand Down
7 changes: 6 additions & 1 deletion vignettes/intro.Rmd
Original file line number Diff line number Diff line change
@@ -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}
Expand All @@ -25,6 +25,9 @@ knitr::opts_chunk$set(fig.width=10, fig.height=4)
options(tidyverse.quiet = TRUE)
```

## Introduction


```{r setup}
library(serosurvey)
```
Expand Down Expand Up @@ -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

0 comments on commit 19ba2e0

Please sign in to comment.