Search code examples
rggplot2survival-analysis

Altering aesthetics for custom table in a ggsurvplot?


I am adding a custom table reporting median survival to a ggsurvplot in R using the code below. As you can see the table appears grey, a bit like the them_gray() theme in ggplot. How does one change the appearance of the table? I am after a clean white table.

library(survival)
library(survminer)
library(ggpp)

# Load the lung cancer survival data
lung <- lung


surv_object <- Surv(lung$time, lung$status)
survfitobj <- survfit(surv_object ~ lung$sex)

km_plot <- ggsurvplot(survfitobj, data = lung)

# Add custom table 

median_df <- as.data.frame(surv_median(survfitobj))


km_plot$plot <- km_plot$plot + ggpp::annotate(geom = "table", x = max(km_plot$data.survplot$time), y = 1.0, label = list(median_df))
km_plot

ggsurvplot with custom table


Solution

  • You could try e.g.

    km_plot$plot <- km_plot$plot + ggpp::annotate(geom = "table", 
                                                  x = max(km_plot$data.survplot$time), 
                                                  table.theme = ttheme_gtbw, 
                                                  y = 1.0, 
                                                  label = list(median_df))
    

    Or

    km_plot$plot <- km_plot$plot + ggpp::annotate(geom = "table", 
                                                  x = max(km_plot$data.survplot$time), 
                                                  table.theme = ttheme_gtbw(colhead = list(bg_params = list(fill = "white"))), 
                                                  y = 1.0, 
                                                  label = list(median_df))
    

    Is that what you are looking for?