Search code examples
rstringvectorsurvival-analysisgtsummary

How can I add a string of Length One with multiple titles?


Current Code:

survfit(Surv(time, DEATH_EVENT) ~ 1, data = HF %>% filter(age <= 70)) %>% 
  tbl_survfit(
    times = c(150,200),
    label_header = "**150 Day survival (95% CI)**"
  )

Output:

How can I add two separate titles to indicate survival times at 150 & 200?

The following code gives me an error:

survfit(Surv(time, DEATH_EVENT) ~ 1, data = HF %>% filter(age <= 70)) %>% 
  tbl_survfit(
    times = c(150,200),
    label_header = c("**150 Day survival (95% CI)**", "**200 Day survival (95% CI)**")
  )

Error: statistic= and label_header= arguments must be strings of length one.


Solution

  • Take a look at the function's help file. The first example solves this issue: you need to use glue-syntax to dynamically insert the day number into the headers.

    https://www.danieldsjoberg.com/gtsummary/reference/tbl_survfit.html

    library(gtsummary)
    library(survival)
    
    # Example 1 ----------------------------------
    # Pass single survfit() object
    tbl_survfit_ex1 <- tbl_survfit(
      survfit(Surv(ttdeath, death) ~ trt, trial),
      times = c(12, 24),
      label_header = "**{time} Month**"
    )
    

    enter image description here