In pursuit of visualizing the distribution of a continuous predictor by survival odds in the sample, I wish to transform the K-M plot as described in my title.
The idea is this way it is easy to see the full range of continuous values. I sacrifice the visualization of overall time distribution of survival, but using colors and maintaining P(Survival) on the y-axis, I could easily plot the 1 year, 5 year survival rate etcetera.
Note I am not looking for Cox visualization. I am interested in the data from a K-M function, i.e.:
km <- survfit(Surv(time, censor) ~ continuous.predictor, data = df)
ggsurvplot(km)
but with the x-axis as the continuous predictor and with lines colored by chosen points in time. Theoretically, this should just be a matter of making factored time the strata and continuous.predictor the new x-value.
However, I am not sure how to do this in R. I have used survfit() in the survival package and ggsurvplot() from survminer but is unclear if either support such a transformation.
 
                        
You could do this using the
predictfunction on your model, supplying the values of the continuous variable and the times at which you wish to measure survival probability.Let's use the
lungexample from the survival package, withageas the continuous variable of interest:Now we create a data frame of all ages 30 - 80 at follow up times of 6 months, 1 year and 5 years:
We can feed this to
predictand get the survival probabilities, with 95% confidence intervals:Now we can plot with vanilla ggplot: