kassambara / survminer

Survival Analysis and Visualization
https://rpkgs.datanovia.com/survminer/
509 stars 164 forks source link

Is it possible to get the p-value per facet in ggsurvplot_facet function #603

Open mavershang opened 2 years ago

mavershang commented 2 years ago

Hello, I have a simple question: in using survminer::ggsurvplot_facet function, how can I get the p-value calculcated per each facet? It's displayed on the plot, but I just want to save it for other analysis. Thanks.

sebastian-gerdes commented 1 year ago

You can easily calculate it yourself with the survdiff function:

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

fit <- survfit( Surv(time, status) ~ sex, data = colon )
ggsurvplot_facet(fit, colon, facet.by = c('rx', 'perfor'), 
                 pval = TRUE, 
                 ggtheme = theme_grey())

# to reproduce the p-value in the upper left and the upper right:
survdiff(Surv(time, status) ~ sex, 
         data = colon, subset = perfor == 0 & rx == 'Obs')$pvalue
survdiff(Surv(time, status) ~ sex, 
         data = colon, subset = perfor == 1 & rx == 'Obs')$pvalue