做多个基因的KM-plot时,每个基因会生成一个KM-plot,会涉及到拼图,主要是利用survminer包里面的arrange_ggsurvplots函数。在这里以TCGA-KIRC数据为例。
gene_list: 为基因列表组成的向量
genelist=c('TSPAN6','TNMD','DPM1','SCYL3')
meta: 临床信息,行名为样本ID,列名为time, event等信息
head(meta[1:4,1:4])
ID event time race
TCGA-CJ-4916 TCGA-CJ-4916 0 45.76667 WHITE
TCGA-B8-A8YJ TCGA-B8-A8YJ 0 0.80000 BLACK OR AFRICAN AMERICAN
TCGA-CJ-5678 TCGA-CJ-5678 1 19.13333 BLACK OR AFRICAN AMERICAN
TCGA-BP-5190 TCGA-BP-5190 0 33.70000 WHITE
exprSet: 标准化(cpm, tpm等)之后的表达矩阵,行名为基因,列名为样本ID
head(exprSet[1:4,1:4])
TCGA-CJ-4916 TCGA-B8-A8YJ TCGA-CJ-5678 TCGA-BP-5190
TSPAN6 4.9486255 5.0688183 5.8483206 5.1387816
TNMD 0.2888252 0.2314566 0.2787592 0.1797391
DPM1 4.4282681 4.7499192 5.0394630 4.0990503
SCYL3 3.7764235 3.3901273 3.2774735 2.9480172
最终代码:
library(survival)
library(survminer)
splots = list()
for(i in 1:length(gene_list)){
x = meta
g = gene_list[i]
x$gene = ifelse(exprSet[g,]> median(exprSet[g,]),'high','low')
sfit1 = survfit(Surv(time, event) ~gene, data = x)
splots[[i]] = ggsurvplot(sfit1, pval = TRUE, palette = "jco",
data = x, legend = c(0.8, 0.8),
title =gene_list[i],risk.table = T)
}
png("survs.png",height = 1200,width = 1200)
arrange_ggsurvplots(splots,nrow = 2, ncol = 2)
dev.off()
拼图效果如下:
代码致谢:生信技能树孙小洁老师
网友评论