其他分享
首页 > 其他分享> > ggsurvplot_combine R语言 一张图内画多条生存曲线

ggsurvplot_combine R语言 一张图内画多条生存曲线

作者:互联网

library(survival)
library(survminer)
#age 分组画生存曲线
fit <- survfit(Surv(time, status) ~ age, data = lung)
summary(fit)
res.cut <- surv_cutpoint(lung, time = "time", event = "status",
                         variables = "age")
summary(res.cut)
res.cat <- surv_categorize(res.cut)
fit_age <- survfit(Surv(time, status) ~age, data = res.cat)
ggsurvplot(fit_age,
           pval = TRUE, 
           #conf.int = TRUE,
           risk.table = TRUE, # Add risk table
           risk.table.col = "strata", # Change risk table color by groups
           surv.median.line = "hv", # Specify median survival
           ggtheme = theme_bw(), # Change ggplot2 theme
           legend.labs = 
             c("old", "young"),    # change legend labels.
           palette = c("#FF6103", "#3D9140")
)

在这里插入图片描述

#wt.loss 分组画生存曲线
fit <- survfit(Surv(time, status) ~  wt.loss, data = lung)
summary(fit)
res.cut <- surv_cutpoint(lung, time = "time", event = "status",
                         variables = "wt.loss")
summary(res.cut)
res.cat <- surv_categorize(res.cut)
fit_wt <- survfit(Surv(time, status) ~ wt.loss, data = res.cat)
ggsurvplot(fit_wt,
           pval = TRUE, 
           #conf.int = TRUE,
           risk.table = TRUE, # Add risk table
           risk.table.col = "strata", # Change risk table color by groups
           surv.median.line = "hv", # Specify median survival
           ggtheme = theme_bw(), # Change ggplot2 theme
           legend.labs = 
             c("old", "young"),    # change legend labels.
           palette = c("blue", "pink")
)

在这里插入图片描述

# sex
fit_sex = survfit(Surv(time, status) ~ sex, data =  lung)
ggsurvplot(fit_sex,
           pval = TRUE, 
           #conf.int = TRUE,
           risk.table = TRUE, # Add risk table
           risk.table.col = "strata", # Change risk table color by groups
           surv.median.line = "hv", # Specify median survival
           ggtheme = theme_bw(), # Change ggplot2 theme
           legend.labs = 
             c("old", "young"),    # change legend labels.
           palette = c("skyblue", "orange")
           )

在这里插入图片描述

# 用ggsurvplot_combine画在一起
fitlist<-list(fit_age,fit_wt,fit_sex)
ggsurvplot_combine(fitlist,data = lung, ggtheme = theme_bw(),
                   palette=c("#FF6103", "#3D9140","blue", "pink","skyblue", "orange")) 

在这里插入图片描述

标签:图内画,fit,sex,ggsurvplot,combine,table,TRUE,risk
来源: https://blog.csdn.net/u013429737/article/details/116245573