## 生存分析
### 應用場景
通常運用于比較不同組別之間生存預后的差異
> 所用數據為TCGA肺腺癌數據,數據結構如下

```R
# 讀取數據,構建生存分析所需數據結構
load('./cli_test.Rdata')#rt_cli
# 按照基因的表達值中位數分成高低表達組
rt_cli$gp[rt_cli[, 'EGFR'] < median(rt_cli[, 'EGFR'])] <- 'low_exp'
rt_cli$gp[rt_cli$gp != 'low_exp'] <- 'high_exp'
# 計算生存的pvalue
library(survival)
diff <- survdiff(Surv(OS_Time, OS_Status) ~ rt_cli$gp, data = rt_cli)
p_value <- 1-pchisq(diff$chisq, df=1)
fit <- survfit(Surv(OS_Time, OS_Status) ~ rt_cli$gp,, data = rt_cli)
```
> 作圖
```R
par(mar = c(5, 5, 5, 3))
plot(fit, lty = 1:1, lwd = 5, cex.main = 2.5, cex.lab = 2.5, col=c("#E7B800", "#2E9FDF"), xlab= ("time (day)"),
ylab="surival rate")
legend('bottomleft', c('high exp', 'low exp'), cex = 1.5, lty = 1, lwd = 7, col=c("#E7B800", "#2E9FDF"))
legend('topright', paste('pvalue:', round(p_value, digits = 2), sep = " "), cex = 1.5)
### 也可以利用survminer這個R包
library(survminer)
ggsurvplot(fit,
conf.int = FALSE,
risk.table.col = "strata", # Change risk table color by groups
ggtheme = theme_bw(), # Change ggplot2 theme
palette = c("#E7B800", "#2E9FDF"))
# 也可以加上95%CI
# conf.int = TRUE
ggsurvplot(fit,
conf.int = TRUE,
risk.table.col = "strata", # Change risk table color by groups
ggtheme = theme_bw(), # Change ggplot2 theme
palette = c("#E7B800", "#2E9FDF"))
# 也可以加上num
ggsurvplot(fit,
conf.int = TRUE,
risk.table.col = "strata", # Change risk table color by groups
ggtheme = theme_bw(), # Change ggplot2 theme
palette = c("#E7B800", "#2E9FDF"),
risk.table = TRUE)
```


- 智匯醫圈
- 第一章 前言
- 1.1 簡介
- 1.2 制作該教程的目的
- 1.3 學習該教程需要掌握的基礎知識
- 1.4 該教程適用人群
- 第二章 散點圖(scatter plot)
- 2.1 基本的散點圖
- 2.2 3D 散點圖
- 第三章 線圖(line plot)
- 3.1 基本的線圖
- 第四章 箱型圖(boxplot)
- 4.1 基本的箱型圖
- 4.2 圖形參數調整
- 4.3 多分組箱型圖
- 4.4 小提琴圖
- 第五章 密度圖(density plot)
- 5.1 基本的密度圖
- 第六章 熱圖(Heatmap)
- 6.1 基本的熱圖
- 6.2 ggplot2 heatmap
- 6.3 相關性熱圖
- 第七章 主成分分析(PCA)
- 7.1 2D PCA
- 7.2 3D PCA
- 第八章 ROC 曲線
- 8.1 基本的 ROC 曲線
- 第九章 生存分析(KM plot)
- 9.1 基本的生存分析
- 第十章 KEGG 和 GO 分析
- 10.1 KEGG 分析
- 10.2 GO 分析
- 第十一章 Circular plot
- 11.1 基本的 Circular plot
- 附錄 下載數據