生存分析,用包自带的数据lung来学习一下,参考survival的帮助文档。
library(survival)
library(survminer)
data('lung')
head(lung)
#> inst time status age sex ph.ecog ph.karno pat.karno meal.cal wt.loss
#> 1 3 306 2 74 1 1 90 100 1175 NA
#> 2 3 455 2 68 1 0 90 90 1225 15
#> 3 3 1010 1 56 1 0 90 90 NA 15
#> 4 5 210 2 57 1 1 90 60 1150 11
#> 5 1 883 2 60 1 0 100 90 NA 0
#> 6 12 1022 1 74 1 1 50 80 513 0
作图前一步都是survfit
fit <- survfit(Surv(time, status) ~ sex, data = lung)
最简单的
ggsurvplot(fit)

显示p值ggsurvplot(fit, pval = TRUE)

修改线型ggsurvplot(fit, pval = TRUE, linetype = 'dashed')

显示置信区间ggsurvplot(fit, pval = TRUE,
conf.int = T,
conf.int.style='ribbon',
conf.int.alpha=0.1)

修改颜色ggsurvplot(fit, pval = TRUE,
conf.int = T,conf.int.style='ribbon',conf.int.alpha=0.1,
palette =c('blue','red'))

修改图例ggsurvplot(fit, pval = TRUE, linetype = 'dashed',
conf.int = T,conf.int.style='ribbon',conf.int.alpha=0.1,
palette =c('blue','red'),
legend.title='',legend=c(0.7,0.9),legend.labs=c('Male','Female'))

再复杂一点ggsurvplot(fit, data = lung,pval = TRUE,
palette = c('#E7B800', '#2E9FDF'),
legend.title = 'Sex',legend.labs = c('Male', 'Female'),
conf.int = TRUE,
surv.median.line = 'hv',
risk.table = TRUE,tables.height = 0.2,tables.theme = theme_cleantable(),
ggtheme = theme_bw()
)
