R语言技巧

for循环批量绘制生存曲线

2020-02-15  本文已影响0人  医科研
### for循环批量绘图
for (i in vars){
 
splots <- list()
km_fit <- survfit(Surv(Survival_months,Vital_Status)~mydata[[i]], data=mydata)
splots[[1]]<-ggsurvplot(km_fit,
           xlab = "Time,mo",
           ylab="Proportion Alive",
           pval = T,
           conf.int = F,##置信带
           risk.table = T,
           legend.title = i,
           legend.labs = levels(mydata[[i]]),##
           #surv.median.line = "hv",# 中位生存
           palette="lancet")
## width=6.95,height=6.5
res<-arrange_ggsurvplots(splots, print = F,
                         ncol = 1, nrow = 1, risk.table.height = 0.25)
ggsave(paste(i,"All_surv.pdf",sep = "_"), res,width=7,height = 6)

# Arrange multiple ggsurvplots and print the output
}
上一篇 下一篇

猜你喜欢

热点阅读