赞
踩
survminer包是生物信息学中实现生存分析曲线绘制最常用的包,包含函数ggsurvplot(),还可使用ggplot2. ggsurvplot() 轻松绘制美观并且格式工整的生存曲线。同时还能给出p值,风险值等参数。
install.packages("survminer")
或者,也可以选择从GitHub上安装
if(!require(devtools)) install.packages("devtools")
devtools::install_github("kassambara/survminer")
加载安装好的包
library("survminer")
#调用生存曲线中另一常用的survival包
require("survival")
#survival包自带肺癌数据集:lung,查看数据样式
head(lung)
#survival包中的Sruv函数可以创建一个生存对象
fit <- survfit(Surv(time, status) ~ 1, data = lung)
#survival包中的survfit函数用Kaplan-Meier法进行生存曲线的拟合
ggsurvplot(fit, color = "#2E9FDF")
require("survival")
fit<- survfit(Surv(time, status) ~ sex, data = lung)
ggsurvplot(fit)
title = “Survival curve” | 设置标题 |
---|---|
font.main | 标题字体大小 |
font.x | x轴标注字体大小 |
font.y | y轴标注字体大小 |
font.tickslab | 坐标轴数字大小 |
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轴的时间间隔
palette = c("#E7B800", "#2E9FDF"), # 自定义调色板
conf.int = TRUE, # 添加置信区间
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轴坐标范围
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"))
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。