How to add P value to autoplot (from the ggfortify package) generating a survival graph

79 Views Asked by At

I am trying to put P value on a survival (Kaplan Meier Plot) using autoplot. The survival plot is generated using survfit from the survival package. I can't use ggsurvplot to generate this graph because ggsurvfit items cannot be placed in multi-panels using plot_grid from cowplot.

Below is my data

structure(list(MLNumber = c("ML01", "ML02", "ML04", "ML06", "ML08", 
"ML09", "ML10", "ML11", "ML13", "ML14", "ML15", "ML16", "ML17", 
"ML19", "ML20", "ML21", "ML22", "ML23", "ML24", "ML25", "ML26", 
"ML27", "ML28", "ML30"), SampleName = c("ML01_1", "ML02-1", "ML04_1", 
"ML06-1", "ML08-1", "ML09 1", "ML10-1", "ML11-1", "ML13 1", "ML14 1", 
"ML15_1", "ML16-1", "ML17-1", "ML19-1", "ML20-1", "ML21_1", "ML22-1", 
"ML23_1", "ML24_1", "ML25_1", "ML26_1", "ML27_1", "ML28_1", "ML30_1"
), New.Condition = c("T0", "T0", "T0", "T0", "T0", "T0", "T0", 
"T0", "T0", "T0", "T0", "T0", "T0", "T0", "T0", "T0", "T0", "T0", 
"T0", "T0", "T0", "T0", "T0", "T0"), AIO_CD8_Tumour = c(951.7134087, 
41.90552818, 3.620258969, 360.3983217, 381.3759689, 33.4182415, 
373.1358038, 270.0080883, 0.855087325, 365.6905343, 0.879070569, 
11.56232469, 345.3665897, 1.723320951, 90.36407338, 355.6611024, 
2.502467173, 291.2494645, 128.1926856, 2279.59354, 4.149084919, 
219.214287, 689.4709034, 11.17489205), AIO_CD8_Stroma = c(984.5569867, 
199.3616873, 25.58947603, 3853.876694, 1482.308676, 41.42941333, 
396.6819461, 470.3319228, 0.171179002, 987.445722, 21.44262625, 
127.1961308, 340.3106622, 3.430218718, 313.5377377, 562.0463814, 
5.246491286, 250.7983636, 283.3006018, 1871.0651, 2.349066537, 
3094.832321, 944.8455957, 17.49450394), PFS_cat = c(1L, 1L, 1L, 
1L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, 
0L, 0L, 1L, 0L, 0L), OS_cat = c(1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 
1L, 0L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, 0L
), months_Os = c(50L, 20L, 49L, 22L, 47L, 16L, 38L, 44L, 1L, 
40L, 19L, 1L, 29L, 33L, 32L, 18L, 9L, 4L, 15L, 14L, 14L, 10L, 
8L, 6L), months_PFS = c(50L, 20L, 36L, 22L, 15L, 2L, 38L, 44L, 
1L, 40L, 7L, 1L, 29L, 33L, 1L, 18L, 9L, 2L, 15L, 14L, 14L, 8L, 
8L, 6L), value = c(951.7134087, 41.90552818, 3.620258969, 360.3983217, 
381.3759689, 33.4182415, 373.1358038, 270.0080883, 0.855087325, 
365.6905343, 0.879070569, 11.56232469, 345.3665897, 1.723320951, 
90.36407338, 355.6611024, 2.502467173, 291.2494645, 128.1926856, 
2279.59354, 4.149084919, 219.214287, 689.4709034, 11.17489205
), category = structure(c(1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 
1L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 1L, 2L), levels = c("high CD8", 
"low CD8"), class = "factor")), row.names = c(NA, -24L), class = "data.frame")

and here is the code I am using

library(ggfortify)
library(survival)
library(pROC)
library(randomForest)
library(survival)
library(survminer)
library(ggplot2)
library(forcats)
library(tidyverse)
library(gtsummary)
library(ggpubr)
library(rstatix)


fc <- df2%>%pull(value) 
pfs <- df2%>%pull(PFS_cat)

plot(x=fc, y=pfs)
glm.fit=glm(pfs~fc, family = binomial)


lines(fc, glm.fit$fitted.values)


par(pty = "s")
rocplot<-roc(pfs, glm.fit$fitted.values, plot = TRUE, legacy.axes = T, ci=TRUE)#AUC 0.7208 %>%
rocplot 



AUC_death <- ggroc(rocplot)+ geom_abline(intercept = 1, slope = 1, linetype = "dashed") + theme_bw() 


AUC_death 

my_roc <- roc(pfs, fc)
thresh<-coords(my_roc, "best", ret = "threshold")#2.331837 %>%
thresh<-thresh %>% pull(threshold) 
thresh 

df2 <- df2 %>% mutate(category = ifelse(value>=thresh, "high CD8", "low CD8"))


df2$category <- factor(df2$category) 


surv_object <- Surv(time = df2$months_PFS, event = df2$PFS_cat)


surv_object

fit2 <- survfit(surv_object ~ category, data = df2)

summary(fit2)

a1 <-  autoplot(fit2, conf.int = FALSE)+
theme(axis.title.x = element_blank())+
  theme(axis.text.x = element_text(angle = 45, hjust = 1))+
  theme(axis.line = element_line(size=1))+
  theme(axis.ticks = element_line(size = 1))+
  theme(text = element_text(size = 14))+
  theme(legend.position = "top")+
  theme(legend.position = "none")+ 
  theme_classic2()+
ggtitle("Progression-free survival-Intrinsic CD8 Density-Tumour")# add p value here 



I have tried "pval= true", p="0.038" to the first like of autoplot but failing.

0

There are 0 best solutions below