survminer包是生物信息學(xué)中實(shí)現(xiàn)生存分析曲線繪制最常用的包,包含函數(shù)ggsurvplot(),還可使用ggplot2. ggsurvplot() 輕松繪制美觀并且格式工整的生存曲線。同時(shí)還能給出p值,風(fēng)險(xiǎn)值等參數(shù)。
install.packages('survminer')
或者,也可以選擇從GitHub上安裝
if(!require(devtools)) install.packages('devtools')
devtools::install_github('kassambara/survminer')
加載安裝好的包
library('survminer')
#調(diào)用生存曲線中另一常用的survival包 require('survival') #survival包自帶肺癌數(shù)據(jù)集:lung,查看數(shù)據(jù)樣式 head(lung) #survival包中的Sruv函數(shù)可以創(chuàng)建一個(gè)生存對(duì)象 fit <- survfit(Surv(time, status) ~ 1, data = lung) #survival包中的survfit函數(shù)用Kaplan-Meier法進(jìn)行生存曲線的擬合 ggsurvplot(fit, color = '#2E9FDF')
require('survival')
fit<- survfit(Surv(time, status) ~ sex, data = lung)
ggsurvplot(fit)
title = “Survival curve” | 設(shè)置標(biāo)題 |
---|---|
font.main | 標(biāo)題字體大小 |
font.x | x軸標(biāo)注字體大小 |
font.y | y軸標(biāo)注字體大小 |
font.tickslab | 坐標(biāo)軸數(shù)字大小 |
ggsurvplot(fit, title = 'Survival curve',
font.title = 18,
font.x = 16,
font.y = 16,
font.tickslab = 14)
ggsurvplot(fit, title = 'Survival curve',
font.title = c(16, 'bold', 'darkblue'),
font.x = c(14, 'bold.italic', 'red'),
font.y = c(14, 'bold.italic', 'darkred'),
font.tickslab = c(12, 'plain', 'darkgreen'))
ggsurvplot(fit, legend = 'bottom',
legend.title = 'Sex',
legend.labs = c('Male', 'Female'))
ggsurvplot(fit, legend = c(0.2, 0.2))
ggsurvplot(fit, size = 1, # 改變曲線的尺寸
linetype = 'strata', # 改變曲線的類型
break.time.by = 250, # 更改x軸的時(shí)間間隔
palette = c('#E7B800', '#2E9FDF'), # 自定義調(diào)色板
conf.int = TRUE, # 添加置信區(qū)間
pval = TRUE # 添加p值
)
ggsurvplot(fit, linetype = 'strata',
conf.int = TRUE, pval = TRUE,
palette = 'grey')
ggsurvplot(fit, pval = TRUE, conf.int = TRUE,
risk.table = TRUE, risk.table.y.text.col = TRUE)
res <- ggsurvplot(fit, pval = TRUE, conf.int = TRUE,
risk.table = TRUE)
res$table <- res$table + theme(axis.line = element_blank())
res$plot <- res$plot + labs(title = 'Survival Curves')
print(res)
ggsurvplot(fit,
pval = TRUE, conf.int = TRUE,
risk.table = TRUE,
risk.table.col = 'strata',
ggtheme = theme_bw(), #改變ggplot2的主題(背景)
palette = 'Dark2',
xlim = c(0, 600))#選取特定的x軸坐標(biāo)范圍
ggsurvplot(fit, conf.int = TRUE,
palette = c('#FF9E29', '#86AA00'),
risk.table = TRUE, risk.table.col = 'strata',
fun = 'event')
ggsurvplot(fit, conf.int = TRUE,
palette = c('#FF9E29', '#86AA00'),
risk.table = TRUE, risk.table.col = 'strata',
fun = 'cumhaz')
ggsurvplot(fit, conf.int = TRUE,
palette = c('#FF9E29', '#86AA00'),
risk.table = TRUE, risk.table.col = 'strata',
pval = TRUE,
fun = function(y) y*100)
ggsurvplot(fit2, pval = TRUE,
break.time.by = 800,
risk.table = TRUE,
risk.table.col = 'strata',
risk.table.height = 0.5,
ggtheme = theme_bw(),
legend.labs = c('A', 'B', 'C', 'D', 'E', 'F'))
聯(lián)系客服