rggplot2themessurvminer

Is it possible to customise the p-value text in Survminer


I am generating survival curves to use in a presentation and ideally I would like to customise the colour of the p value text. Is it possible to do that? I have made an example with sample data to show you what I have done so far. All that remains is the colour of the p value text to #5A6469 but I've tried pretty much every option and it's stayed resolutely black! Thank you for your assistance.

library(tidyverse)
library(survival)
library(survminer)

# theme using custom colour palette and with transparent background because the slides are grey
theme_kcl <- theme_classic() + theme(plot.title = element_text(colour = "#0A2D50", size = 16, hjust = 0.5), axis.title = element_text(colour = "#0A2D50", size = 14), axis.title.x = element_text(margin = margin(t = 10, r = 0, b = 0, l = 0)), axis.title.y = element_text(margin = margin(t = 0, r = 10, b = 0, l = 0)), axis.text = element_text(colour = "#5A6469", size = 12), legend.text = element_text(colour = "#5A6469", size = 12)) + theme(axis.ticks.x = element_line(colour = "#5A6469"), axis.ticks.y = element_line(colour = "#5A6469"), axis.line = element_line(colour = "#0A2D50")) + theme(panel.background = element_rect(fill = "transparent", colour = NA), plot.background = element_rect(fill = "transparent", colour = NA), legend.background = element_rect(fill = "transparent", colour = NA))

# Fit example data
fit<- survfit(Surv(time, status) ~ sex, data = lung)

# Draw survival curves
ggsurvplot(fit, palette = c("#C83296", "#009EA0"), pval = TRUE, legend = c(0.84, 0.8), legend.title = "", ggtheme = theme_kcl)

Solution

  • Yes.

    Start by storing your plot in j

    j <- ggsurvplot(fit, palette = c("#C83296", "#009EA0"), pval = FALSE, legend = c(0.84, 0.8), legend.title = "", ggtheme = theme_kcl)
    

    I changed pval=FALSE as you are about to add the p-value text manually.

    If you need to perform af log-rank test to estimate your p-value, simply type

    survdiff(Surv(time, status) ~ sex, data = lung)
    

    Then

    j$plot <- j$plot +
         annotate("text", x = 10, y = 15, label = "P-value", cex=3.3, col="darkgrey", vjust=0, hjust = 1.1, fontface=2)
    
    j
    

    Simply just change the (x,y)-coordinates. Edit or design the text as you like.