R基础-08.任意基因任意癌症表达量分组的生存分析
参考视频【生信技能树】生信人应该这样学R语言
代码为自己学习总结
由于工作上的一些事情,R基础学习断更快一周了,今天补起
1、读取数据
rm(list = ls())
options(stringsAsFactors = F)
#http://www.oncolnc.org/kaplan/?lower=50&upper=50&cancer=LGG&gene_id=93663&raw=ARHGAP18&species=mRNA
a=read.csv('LGG_93663_50_50.csv',header = T,sep = ',',fill = T)
colnames(a)
dat=a
2、加载绘图相关的R包
library(BiocManager)
#BiocManager::install("ggstatsplot")#通过软件安装包安装
BiocManager::install("metaBMA")
library(ggstatsplot)
ggbetweenstats(data = dat, x = Group, y = Expression)
Rplot.png
library(ggplot2)
library(survival)
BiocManager::install("survminer")
library(survminer)
table(dat$Status)
dat$Status=ifelse(dat$Status=='Dead',1,0)
sfit<- survfit(Surv(Days, Status)~Group,data =dat)
sfit
summary(sfit)
ggsurvplot(sfit,conf.int=F,pval = TRUE)
Rplot01.png
ggsave('survial_ARHGAP18_in_LGG.png')
survial_ARHGAP18_in_LGG.png
ggsurvplot(sfit,palette = c("#E7B800","#2E9FDF"),
risk.table = TRUE, pval = TRUE, conf.int= TRUE,xlab = "Time in months",
ggtheme = theme_light(),ncensor.plot = TRUE)
#ggsave('survial_ARHGAP18_in_LGG.png')
Rplot02.png
番外篇:本篇为上周四(20190711)晚上的学习内容,由于安装ggstatsplot时依赖的rstan的R报错(Error in .shlib_internal(args) : C++14 standard requested but CXX14 is not defined * removing 'C:/Users/ljx/Documents/R/win-library/3.6/rstan' Warning in install.packages : installation of package ‘rstan’ had non-zero exit status
),最后发现是rstan对应的R包地址有问题,直接去R官网下载rstan的之前的版本,完美解决ggstatsplot安装问题