美文网首页美文共赏
内容最详细的生存曲线画法

内容最详细的生存曲线画法

作者: 小白兔和小毛驴 | 来源:发表于2021-12-09 21:26 被阅读0次

    fit <- survfit(Surv(time, status) ~ sex, data=lung)

    p1 <- ggsurvplot(fit)

    p2 <- ggsurvplot(fit, data = lung,

                    surv.median.line = "hv", #添加中位生存曲线

                    palette=c("red", "blue"),  #更改线的颜色

                    legend.labs=c("Sex1","Sex2"), #标签

                    legend.title="Treatment",

                    title="Overall survival", #标题

                    ylab="Cumulative survival (percentage)",xlab = " Time (Days)", #更改横纵坐标

                    censor.shape = 124,censor.size = 2,conf.int = FALSE, #删失点的形状和大小

                    break.x.by = 100#横坐标间隔

    )

    p3 <- ggsurvplot(fit, data = lung,

                    surv.median.line = "hv", #添加中位生存曲线

                    palette=c("red", "blue"),

                    legend.labs=c("Sex1","Sex2"), #标签

                    legend.title="Treatment",

                    title="Overall survival",

                    ylab="Cumulative survival (percentage)",xlab = " Time (Days)", #更改横纵坐标

                    censor.shape = 124,censor.size = 2,conf.int = FALSE,

                    break.x.by = 100,

                    risk.table = TRUE,tables.height = 0.2,

                    tables.theme = theme_cleantable(),

                    ggtheme = theme_bw())

    P4 <- ggsurvplot(fit, data = lung,

                    pval = TRUE,#添加P值

                    pval.coord = c(0, 0.03), #调节Pval的位置

                    surv.median.line = "hv", #添加中位生存曲线

                    palette=c("red", "blue"),

                    legend.labs=c("Sex1","Sex2"), #标签

                    legend.title="Treatment",

                    title="Overall survival",

                    ylab="Cumulative survival (percentage)",xlab = " Time (Days)", #更改横纵坐标

                    censor.shape = 124,censor.size = 2,conf.int = FALSE,

                    break.x.by = 100,

                    risk.table = TRUE,tables.height = 0.2,

                    tables.theme = theme_cleantable(),

                    ggtheme = theme_bw())

    ###添加COX回归hazard ratio值相关信息

    res_cox<-coxph(Surv(time, status) ~sex, data=lung)

    p3$plot = p3$plot + ggplot2::annotate("text",x = 50, y = 0.15,

                                          label = paste("HR :",round(summary(res_cox)$conf.int[1],2))) + ggplot2::annotate("text",x = 50, y = 0.10,

                                                                                                                          label = paste("(","95%CI:",round(summary(res_cox)$conf.int[3],2),"-",round(summary(res_cox)$conf.int[4],2),")",sep = ""))+

      ggplot2::annotate("text",x = 50, y = 0.05,

                        label = paste("P:",round(summary(res_cox)$coef[5],4)))

    相关文章

      网友评论

        本文标题:内容最详细的生存曲线画法

        本文链接:https://www.haomeiwen.com/subject/gsdhfrtx.html