Create a ggplot2 survival curve with censored table

后端 未结 2 792
轮回少年
轮回少年 2021-01-26 15:44

I am trying to create a Kaplan-Meier plot with 95% confidence bands plus having the censored data in a table beneath it. I can create the plot, but not the table. I get the erro

2条回答
  •  无人共我
    2021-01-26 16:30

    Here's a start (code below)

    I guess you can create the table need and replace it by the random.table

    # install.packages("ggplot2", dependencies = TRUE)
    # install.packages("RGraphics", dependencies = TRUE)
    # install.packages("gridExtra", dependencies = TRUE)
    # install.packages("survival", dependencies = TRUE)
    
    require(ggplot2)
    library(RGraphics)
    library(gridExtra)
    library(survival)
    
    # Plot
       data(lung) 
       sf.sex <- survfit(Surv(time, status) ~ sex, data = lung) 
       pl.sex <- ggsurv(sf.sex) +
       geom_ribbon(aes(ymin=low,ymax=up,fill=group),alpha=0.3) +
       guides(fill=guide_legend("sex"))
    
    # Table
    random.table <- data.frame("CL 95"=rnorm(5),n=runif(5,1,3))
    pl.table <- tableGrob(random.table)
    
    # Arrange the plots on the same page
    grid.arrange(pl.sex, pl.table, ncol=1)
    

提交回复
热议问题