diff --git a/DESCRIPTION b/DESCRIPTION index 44a09cc..fa418f0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -14,6 +14,7 @@ Depends: R (>= 4.1.0) Imports: clock, + collapse, dplyr, fixtuRes, fs, @@ -31,6 +32,8 @@ Suggests: fuimus, ggforce, ggplot2, + ggalt, + ggrepel, ggthemes, gt, gtExtras, diff --git a/R/generated-globals.R b/R/generated-globals.R index 34fecdb..f0cddd2 100644 --- a/R/generated-globals.R +++ b/R/generated-globals.R @@ -8,6 +8,7 @@ utils::globalVariables(c( # "age", # + # "aging_bin", # "balance", diff --git a/R/parbx.R b/R/parbx.R index 4ffafd0..384cb86 100644 --- a/R/parbx.R +++ b/R/parbx.R @@ -1,4 +1,8 @@ #' Generate Mock PARBx data +#' @param payer `[character]` vector of payer names +#' @param ... `[dots]` additional arguments +#' @return A [tibble][tibble::tibble-package] +#' #' @keywords internal #' #' @examples @@ -9,7 +13,7 @@ #' "Coventry", "Medicaid", "Centene", #' "CVSHealth")) #' -#' +#' @autoglobal #' @export parbx_ex <- function(payer, ...) { diff --git a/R/print.R b/R/print.R index df653b5..94cb383 100644 --- a/R/print.R +++ b/R/print.R @@ -5,7 +5,9 @@ print.forager <- function(x, ...) { list( pillar.bold = TRUE, pillar.subtle_num = TRUE, - pillar.print_min = 20 + pillar.width = getOption("width"), + pillar.min_title_chars = 8, + pillar.sigfig = 2 ), NextMethod() ) diff --git a/man/parbx_ex.Rd b/man/parbx_ex.Rd index 8bac90a..964d968 100644 --- a/man/parbx_ex.Rd +++ b/man/parbx_ex.Rd @@ -6,6 +6,14 @@ \usage{ parbx_ex(payer, ...) } +\arguments{ +\item{payer}{\verb{[character]} vector of payer names} + +\item{...}{\verb{[dots]} additional arguments} +} +\value{ +A \link[tibble:tibble-package]{tibble} +} \description{ Generate Mock PARBx data } @@ -17,6 +25,5 @@ parbx_ex( "Coventry", "Medicaid", "Centene", "CVSHealth")) - } \keyword{internal} diff --git a/vignettes/articles/testss.Rmd b/vignettes/articles/testss.Rmd index 67d7da6..cfb648b 100644 --- a/vignettes/articles/testss.Rmd +++ b/vignettes/articles/testss.Rmd @@ -17,6 +17,9 @@ options(scipen = 999) library(forager) library(dplyr) +library(lubridate) +library(clock) +library(tidyr) library(ggplot2) library(ggforce) library(scales) @@ -111,15 +114,40 @@ ggplot(old, aes(y = aging_bin, x = balance)) + ```{r} -load_ex("aging_biweekly") |> - gt::gt_preview() |> - opt_table_font(font = google_font(name = "Fira Code")) +biweekly <- load_ex("aging_biweekly") |> + mutate(year = get_year(date), + month = date_month_factor(date, abbreviate = TRUE), + .after = date) |> + arrange(date, aging_bin) + +ggplot(data = biweekly, + aes(x = forcats::fct_rev(aging_bin), y = balance, fill = date)) + + geom_col(position = position_stack(reverse = TRUE)) + + # geom_col(position = position_fill(reverse = TRUE)) + + coord_flip(clip = "off") + + labs(title = NULL, x = NULL) + + ggthemes::scale_color_fivethirtyeight() + + ggthemes::theme_fivethirtyeight(base_size = 10) + + theme(legend.position = "none", + axis.text.x = element_blank(), + axis.text.y = element_text(size = 12, face = "bold") + ) ``` + + ```{r} -load_ex("aging_ex") |> +agingex <- load_ex("aging_ex")[1:4] |> + days_between(dos) |> + bin_aging(days_elapsed) |> + mutate(year = get_year(dos), + quarter = get_quarter(as_year_quarter_day(dos)), + month = date_month_factor(dos), + .after = dos) + +agingex |> gt::gt_preview() |> opt_table_font(font = google_font(name = "Fira Code")) ``` diff --git a/vignettes/getting-started.Rmd b/vignettes/getting-started.Rmd index fd07f34..f6eeb09 100644 --- a/vignettes/getting-started.Rmd +++ b/vignettes/getting-started.Rmd @@ -26,6 +26,8 @@ library(tidyr) library(gt) library(gtExtras) library(ggplot2) +library(ggrepel) +library(ggalt) library(scales) library(headliner) ``` @@ -95,10 +97,11 @@ dar_mon |> ```{r} dar_mon |> - ggplot(aes(x = mon, y = dar)) + + ggplot(aes(x = date, y = dar)) + geom_line(group = 1, linetype = "dashed", alpha = 0.7) + geom_hline(yintercept = 35, color = "red") + labs(title = "Days in AR by Month", x = NULL, y = NULL) + + scale_x_date(date_breaks = "1 month", date_labels = "%b") + ggthemes::scale_color_fivethirtyeight() + ggthemes::theme_fivethirtyeight(base_size = 10) ``` @@ -114,9 +117,9 @@ dar_ex() |> color = "red", alpha = 0.7, linewidth = 1.5) + - scale_y_continuous(labels = dollar_format(prefix = "$")) + + labs(title = "Gross Charges & Ending AR Balance by Month", x = NULL, y = NULL) + + scale_y_continuous(labels = dollar_format(prefix = "$", scale = 0.001, suffix = "k")) + scale_x_date(date_breaks = "1 month", date_labels = "%b") + - labs(title = NULL, x = NULL, y = NULL) + ggthemes::scale_color_fivethirtyeight() + ggthemes::theme_fivethirtyeight(base_size = 10) ``` @@ -150,7 +153,7 @@ dar_mon <- dar_mon |> dar_mon |> ggplot(aes(x = earb, y = dar)) + - geom_point(aes(colour = dar > 35), show.legend = FALSE) + + geom_point(aes(fill = dar > 35), show.legend = FALSE, size = 5, stroke = 1, shape = 21) + geom_hline(yintercept = 35, color = "red", alpha = 0.5) + scale_x_continuous( labels = dollar_format(scale = 0.001, suffix = "k"), @@ -358,6 +361,33 @@ binned <- load_ex("aging_ex") |> binned ``` + +```{r fig.height=8, fig.width=10, fig.dpi=600} +binned |> + # filter(charges > mean(charges)) |> + ggplot() + + geom_point(aes(x = dos, y = charges, fill = aging_bin), size = 3.5, shape = 21, stroke = 0.6) + + ggalt::geom_spikelines(data = binned |> group_by(aging_bin) |> filter(charges == max(charges)), + aes(x = dos, y = charges, fill = aging_bin), linetype = 3) + + ggrepel::geom_label_repel(data = binned |> + group_by(aging_bin) |> + filter(charges == max(charges)), + aes(x = dos, y = charges, label = ins_name)) + + labs(title = "Aging Bins", x = NULL, y = NULL) + + scale_y_continuous( + labels = dollar_format(prefix = "$"), + limits = c(min(binned$charges), max(binned$charges) + 10)) + + scale_x_date(date_breaks = "1 week", date_labels = "%W") + + ggthemes::scale_color_fivethirtyeight() + + ggthemes::theme_fivethirtyeight(base_size = 12) + + theme(legend.position = "top", + axis.text.x = element_text(size = 10, face = "bold"), + axis.text.y = element_text(size = 12, face = "bold") + ) +``` + + + ```{r} binned |> arrange(aging_bin) |>