-不删掉unknow,空白等改为unknow
-Age:分为<=65和>65两组
-Grade:GX改为unknow
-Stage:Stage IA和Stage IB均改为Stage I,依次类推
-T,M,N:T1A,M1A,N1A改为T1,M1,N1,依次类推TX,MX,NX改为unknow
然后新建clinical.txt,将上图内容粘贴进去
#引用包
library(limma)
library(ggpubr)
riskFile="risk.txt" #风险文件
cliFile="clinical.txt" #临床数据文件
setwd("E:\\research") #修改工作目录
#读取风险文件
risk=read.table(riskFile, header=T, sep="\t", check.names=F, row.names=1)
#读取临床数据文件
cli=read.table(cliFile, header=T, sep="\t", check.names=F, row.names=1)
#合并数据
samSample=intersect(row.names(risk), row.names(cli))
risk=risk[samSample,"riskScore",drop=F]
cli=cli[samSample,,drop=F]
rt=cbind(risk, cli)
#临床相关性分析,输出图形结果
for(clinical in colnames(rt[,2:ncol(rt)])){
data=rt[c("riskScore", clinical)]
colnames(data)=c("riskScore", "clinical")
data=data[(data[,"clinical"]!="unknow"),]
#设置比较组
group=levels(factor(data$clinical))
data$clinical=factor(data$clinical, levels=group)
comp=combn(group,2)
my_comparisons=list()
for(i in 1:ncol(comp)){my_comparisons[[i]]<-comp[,i]}
#绘制箱线图
boxplot=ggboxplot(data, x="clinical", y="riskScore", color="clinical",
xlab=clinical,
ylab="Risk score",
legend.title=clinical,
add = "jitter")+
stat_compare_means(comparisons = my_comparisons)
#输出图片
pdf(file=paste0(clinical, ".pdf"), width=5.5, height=5)
print(boxplot)
dev.off()
}