rggplot2survival-analysisinterceptgeom-vline

How to add vertical lines and annotation to survival plot with risk table (R)


I want to have a survival plot with a risk table with a vertical line at 12 months and 36 months. Initially I was able to go this

figure1$plot + geom_vline(xintercept = 12) + geom_vline(intercept = 36)

However when I want to add the risk table as follows

figure1$plot + figure1$table + geom_vline(xintercept = 12) + geom_vline(intercept = 36)

I get the error message of "Don't know how to add figure1$table to a plot"

Any recs?


Solution

  • Your question is not very clear - it is unclear what you have tried, which package you used, etc..

    I am guessing you are using survminer and are trying to modify the plot object and plot it together with the risk table. The way you would do this is shown in the reproducible example below:

    library(survminer)
    library(survival)
    fit <- survfit(Surv(time, status) ~ sex, data = lung)
    p1 <- ggsurvplot(fit, risk.table = TRUE) 
    p1$plot <- p1$plot + 
      geom_vline(xintercept = 250) + 
      geom_vline(xintercept = 360)
    p1
    

    Created on 2020-04-21 by the reprex package (v0.3.0)