使用R绘制生存曲线

一、加载程序包

1
2
3
4
library(survival)
library(ggplot2)
library(survminer)
library(dplyr)

二、加载数据并绘图

1
data <- read.delim('clipboard',header = T)
1
2
3
4
5
6
7
8
head(data)
Patient Days Status Expression Group
1 TCGA-B0-5702 2172 Alive 383.07 Low
2 TCGA-B0-4696 866 Dead 810.35 Low
3 TCGA-B0-4698 42 Dead 849.64 Low
4 TCGA-CJ-4642 3205 Alive 1153.28 Low
5 TCGA-BP-5185 1132 Alive 1197.89 Low
6 TCGA-BP-4337 2 Dead 1223.26 Low
1
table(data$Status)
1
2
Alive  Dead 
349 173
1
table(data$Group,data$Status)
1
2
3
      Alive Dead
High 198 63
Low 151 110
1
my.surv <- Surv(data$Days,data$Status=='Dead')
1
fit <- survfit(my.surv~data$Group)
1
2
3
4
5
Call: survfit(formula = my.surv ~ data$Group)

n events median 0.95LCL 0.95UCL
data$Group=High 261 63 NA 2830 NA
data$Group=Low 261 110 1980 1620 2601

绘制最基本的生存曲线

1
plot(fit,col=c("red","blue"))

优化生存曲线

1
2
3
4
5
6
7
8
plot(kmfit2,col=c("red","blue"),axes=F,xlab="Days",ylab="Survival",lwd=2,main="Kidney Renal Clear Cell Carcinoma")
axis(2,at=c(0,0.5,1),labels=c(0,0.5,1),pos=0,las=2)
axis(1,at=c(0,1000,2000,3000,4000,5000),labels=c(0,1000,2000,3000,4000,5000),pos=0)
segments(2190,0,2190,0.5,lty=2,col="red")
segments(0,0.5,3615,0.5,lty=2,col="grey")
segments(3615,0,3615,0.5,lty=2,col="blue")
text(1500,0.95,"p=0.000598",cex=0.8)
legend("topright",c("High","Low"),fill=c("red","blue"),cex=0.9,bty="n",box.lwd=0.2)

  • 本文作者:括囊无誉
  • 本文链接: R/R_survival_curve/
  • 版权声明: 本博客所有文章均为原创作品,转载请注明出处!
------ 本文结束 ------
坚持原创文章分享,您的支持将鼓励我继续创作!