jthomasmock / gtExtras

A Collection of Helper Functions for the gt Package.
https://jthomasmock.github.io/gtExtras/
Other
195 stars 27 forks source link

Adding "Identity Boxplot" to gt_plt_dist() #136

Open beansrowning opened 1 month ago

beansrowning commented 1 month ago

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

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