gtExtras icon indicating copy to clipboard operation
gtExtras copied to clipboard

Adding "Identity Boxplot" to gt_plt_dist()

Open beansrowning opened this issue 1 year ago • 0 comments

Rationale

I use R (or Python) for ETL and write simple summary statistics while processing the data. I recently wanted to visualize a five-num summary I wrote out for each dataset as a boxplot within a {gt} table, but found that {gtExtras} didn't allow this natively, since it's always assumed that the full set of data is present in the list col passed. In my case, it is not always possible to include the full dataset--nor advisable, due to size--but I'd still like to construct rudimentary boxplots in my table.

It seems like an easy addition, since {ggplot2} already allows this behavior natively (and {sparkline} does as well via spk_chr(., type="box", raw=TRUE)).

Changes

  • Adds an additional type to gt_plt_dist() called "boxplot_identity" that allows a user to pass variables to define boxplot via ggplot's stat="identity" option rather than raw data
  • Updated unit tests
  • Updated docs

Example:

mtcars |>
  dplyr::group_by(cyl) |>
  dplyr::summarize(mpg_data = list(stats::fivenum(mpg)), .groups = "drop") |>
  gt() |>
  gt_plt_dist(mpg_data, type = "boxplot_identity")

image

beansrowning avatar Sep 18 '24 17:09 beansrowning