Skip to content

Commit

Permalink
dataviz experiments
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewallenbruce committed Jun 6, 2024
1 parent c3a88a5 commit 29aa015
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 11 deletions.
3 changes: 3 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Depends:
R (>= 4.1.0)
Imports:
clock,
collapse,
dplyr,
fixtuRes,
fs,
Expand All @@ -31,6 +32,8 @@ Suggests:
fuimus,
ggforce,
ggplot2,
ggalt,
ggrepel,
ggthemes,
gt,
gtExtras,
Expand Down
1 change: 1 addition & 0 deletions R/generated-globals.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ utils::globalVariables(c(
# <generate_data>
"age",
# <bin_aging>
# <parbx_ex>
"aging_bin",
# <generate_data>
"balance",
Expand Down
6 changes: 5 additions & 1 deletion R/parbx.R
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,7 +13,7 @@
#' "Coventry", "Medicaid", "Centene",
#' "CVSHealth"))
#'
#'
#' @autoglobal
#' @export
parbx_ex <- function(payer, ...) {

Expand Down
4 changes: 3 additions & 1 deletion R/print.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
Expand Down
9 changes: 8 additions & 1 deletion man/parbx_ex.Rd

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

36 changes: 32 additions & 4 deletions vignettes/articles/testss.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ options(scipen = 999)
library(forager)
library(dplyr)
library(lubridate)
library(clock)
library(tidyr)
library(ggplot2)
library(ggforce)
library(scales)
Expand Down Expand Up @@ -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"))
```
Expand Down
38 changes: 34 additions & 4 deletions vignettes/getting-started.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ library(tidyr)
library(gt)
library(gtExtras)
library(ggplot2)
library(ggrepel)
library(ggalt)
library(scales)
library(headliner)
```
Expand Down Expand Up @@ -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)
```
Expand All @@ -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)
```
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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) |>
Expand Down

0 comments on commit 29aa015

Please sign in to comment.