ddsjoberg / gtsummary

Presentation-Ready Data Summary and Analytic Result Tables
http://www.danieldsjoberg.com/gtsummary
Other
1.05k stars 124 forks source link

pharma theme? #2005

Closed ddsjoberg closed 1 month ago

ddsjoberg commented 1 month ago

I think we could do something as simple as the compact theme + gt::opt_table_font(stack = "monospace-code") (and one for flextable, maybe)?

ddsjoberg commented 1 month ago

Something like this could work? Not sure about it though

theme_gtsummary_pharma <- function(set_theme = TRUE, font_size = NULL) {
  # start with the compact theme -----------------------------------------------
  lst_theme <- theme_gtsummary_compact(set_theme = FALSE, font_size = font_size)
  lst_theme$`pkgwide-str:theme_name` <- "Pharmaceutical"

  # updating with some pharma-specific bits ------------------------------------
  lst_theme <- lst_theme |>
    append(
      list(
        "tbl_summary-str:default_con_type" = "continuous2",
        "tbl_summary-arg:statistic" =
          list(all_continuous() ~ c("{median} ({p25}, {p75})", "{mean} ({sd})", "{min}, {max}"),
               all_categorical() ~ "{n} ({p}%)"),
        "tbl_summary-fn:percent_fun" = label_style_percent(digits = 1),
        "pkgwide-fn:pvalue_fun" = label_style_pvalue(digits = 2),
        "tbl_summary-fn:addnl-fn-to-run" = function(x) add_stat_label(x) |> bold_labels()
      )
    )

  # add a monospace font for gt ------------------------------------------------
  lst_theme$`as_gt-lst:addl_cmds` <-
    c(lst_theme$`as_gt-lst:addl_cmds`,
      list(tab_spanner = expr(gt::opt_table_font(stack = "monospace-code"))))

  # finishing up ---------------------------------------------------------------
  if (set_theme == TRUE) set_gtsummary_theme(lst_theme)
  return(invisible(lst_theme))
}

theme_gtsummary_pharma()
tbl_summary(trial, by = trt, include = c(age, grade, response)) |> add_p()
image
ddsjoberg commented 1 month ago

Added a proto-type here: https://insightsengineering.github.io/crane/reference/theme_gtsummary_roche.html

Will develop it there, and perhaps migrate here one day?