Kaplan-Meier by strata in survminer, but the risk table not by strata

204 Views Asked by At

I am creating a KM plot using survminer:

survfit(Surv(tte, event) ~ trt, data = data) %>%
  ggsurvplot(
    risk.table = TRUE,
    risk.table.pos = "in"
  )

This gives a KM curve split by trt, but the risk table is also split by trt too. Is there a way that I can just have the total number across all groups in the risk table, but keep the strata for the plot it's self?

1

There are 1 best solutions below

0
stefan On

As ggsurvplot object is basically a list containing the plot of the survival curve as an element named plot and the risk table as an element table. Hence, one option to achieve your desired result would be to creat two ggsurvplot object, one stratified by group, one for both or all groups. Afterwards you could take the plot element from the first and the table element from the second.

Using the default example from ?ggsurvplot:

library(survminer)
#> Loading required package: ggplot2
#> Loading required package: ggpubr
library(survival)
#> 
#> Attaching package: 'survival'
#> The following object is masked from 'package:survminer':
#> 
#>     myeloma

plot <- survfit(Surv(time, status) ~ sex, data = lung) |> 
  ggsurvplot(
    risk.table = TRUE,
    risk.table.pos = "in"
  )

table <- survfit(Surv(time, status) ~ 1, data = lung) |> 
  ggsurvplot(
    risk.table = TRUE,
    risk.table.pos = "in",
    palette = "blue"
  )

plot$plot <- plot$plot
plot$table <- table$table

plot