I come accross this months later as I am confronted with a similar question. Here are the different solutions I found.
First, as mentioned by @IRTFM, the code to produce your plot:
library("survminer")
data=colon
fit2 <- survfit(Surv(time, status) ~ sex + rx,data = colon)
ggsurvplot_facet(fit2,colon,facet.by = "adhere",palette="jco",pval=TRUE)
Solution 1:
First, we look at fit2
> fit2
Call: survfit(formula = Surv(time, status) ~ sex + rx, data = colon)
n events median 0.95LCL 0.95UCL
sex=0, rx=Obs 298 158 1981 1272 NA
sex=0, rx=Lev 266 137 1885 1275 NA
sex=0, rx=Lev+5FU 326 149 NA 2021 NA
sex=1, rx=Obs 332 187 1539 1195 2284
sex=1, rx=Lev 354 196 1548 1061 2593
sex=1, rx=Lev+5FU 282 93 NA NA NA
We can extract the strata of interest:
ggsurvplot(fit2[c(1,4)], colon, palette="jco",pval=TRUE)
Solution 2: for longer survfit objects, it can be tedious to grab the strata indexes, so we could use :
ggsurvplot(fit2[c(which(attr(fit2$strata,which="names")=="sex=0, rx=Obs " | attr(fit2$strata,which="names")=="sex=1, rx=Obs "))],
colon, palette="jco",pval=TRUE)
The results is the same graph as in solution 1 of course.
R is case (and space) sensitive, so the exact spelling of the strata can be extracted/checked with:
> attr(fit2$strata,"names")
[1] "sex=0, rx=Obs " "sex=0, rx=Lev " "sex=0, rx=Lev+5FU" "sex=1, rx=Obs " "sex=1, rx=Lev " "sex=1, rx=Lev+5FU"
Here, there are 3 spaces after "rx=Obs "
Solution 3: as suggested by @IRTFM, we can subset the data set (with rx and sex, not adhere). However, the p-value changes! In this case, I believe that not all data are used in the model, unlike the other solutions (? to be confirmed, if someone knows the details inside the calculation):
fit3 <- survfit( Surv(time, status) ~ rx + sex, data = colon, subset = rx == "Obs" )
> fit3
Call: survfit(formula = Surv(time, status) ~ rx + sex, data = colon,
subset = rx == "Obs")
n events median 0.95LCL 0.95UCL
rx=Obs, sex=0 298 158 1981 1272 NA
rx=Obs, sex=1 332 187 1539 1195 2284
ggsurvplot(fit3, colon, palette="jco",pval=TRUE)
Solution 4:
Instead of subsetting, one can also use
fit4 <- survfit( Surv(time, status) ~ rx + sex, data = colon[colon$rx=="Obs",])
fit4
Call: survfit(formula = Surv(time, status) ~ rx + sex, data = colon[colon$rx ==
"Obs", ])
n events median 0.95LCL 0.95UCL
rx=Obs, sex=0 298 158 1981 1272 NA
rx=Obs, sex=1 332 187 1539 1195 2284
ggsurvplot(fit4, colon, palette="jco",pval=TRUE)
The p-value is, however, similar as in solution 1 and 2 (p<0.0001)
We can still facet the plot:
ggsurvplot_facet(fit4,data = colon[colon$rx=="Obs",],facet.by = "adhere",palette="jco",pval=TRUE)