How to modify header in r using gtsummary package?

1.9k views Asked by At

Hopefully, a simple answer that someone knows off the top of their head!

I am using tbl_summary and trying to modify my header to have n(%) instead of the standard format of N = 57. I would normally use modify_header(stat_by) but can't when by isn't included.

Example:

trial %>%
  select(trt, marker, stage) %>%
  tbl_summary() %>%
  modify_header(stat_by = "**{level}**, n(%)")

Any ideas most appreciated!

1

There are 1 answers

2
kittykatstat On BEST ANSWER

To edit the text of your header, you can use the update argument in modify_header(). stat_0 refers to the statistic column, so this is the one you need to change:

library(gtsummary)

trial %>%
  select(trt, marker, stage) %>%
  tbl_summary() %>%
  modify_header(update = stat_0 ~ "**n(%)**")

You can use {glue} syntax if you want to insert a statistic as well:

trial %>%
  select(trt, marker, stage) %>%
  tbl_summary() %>%
  modify_header(update = stat_0 ~ "**n(%), N = {N}**")

Good luck!