Sylv
Sylv

Reputation: 51

How to modify header in r using gtsummary package?

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!

Upvotes: 1

Views: 2522

Answers (1)

kittykatstat
kittykatstat

Reputation: 578

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!

Upvotes: 2

Related Questions