Plotting survival curves in R with ggplot2

后端 未结 2 2010
-上瘾入骨i
-上瘾入骨i 2020-12-16 02:31

I\'ve been looking for a solution to plot survival curves using ggplot2. I\'ve found some nice examples, but they do not follow the whole ggplot2 aesthetics (mainly regardin

2条回答
  •  攒了一身酷
    2020-12-16 03:22

    You could try the following for something with shaded areas between CIs:

    (I'm using the development version here as there's a flaw with the parameter alpha in the production version (doesn't shade upper rectangles correctly for non-default values). Otherwise the functions are identical).

    library(devtools)
    dev_mode(TRUE) # in case you don't want a permanent install
    install_github("survMisc", "dardisco")
    library("survMisc", lib.loc="C:/Users/c/R-dev") # or wherever you/devtools has put it
    data(kidney, package="KMsurv")
    p1 <- autoplot(survfit(Surv(time, delta) ~ type, data=kidney),
                   type="fill", survSize=2, palette="Pastel1",
                   fillLineSize=0.1, alpha=0.4)$plot
    p1 + theme_classic()
    dev_mode(FALSE)
    

    giving:

    enter image description here

    And for a classic plot and table:

    autoplot(autoplot(survfit(Surv(time, delta) ~ type, data=kidney),
                      type="CI"))
    

    enter image description here

    See ?survMisc::autoplot.survfit and ?survMisc::autoplot.tableAndPlot for more options.

提交回复
热议问题