library(ggpubr)
setwd("/Users/Desktop/生物信息学/测试") #数据要整齐 不能有空缺数值或na
rt=read.table("cl.txt",sep="\t",header=T,check.names=F,row.names=1)
rt
gene=colnames(rt)[3] #获取基因名字
#临床相关分析
for(clinical in colnames(rt[,4:ncol(rt)])){
data=rt[c(gene,clinical)]
colnames(data)=c("gene","clinical")
#设置比较组
group=levels(factor(data$clinical))
comp=combn(group,2)
my_comparisons=list()
for(i in 1:ncol(comp)){my_comparisons[[i]]<-comp[,i]}
#绘制boxplot
boxplot=ggboxplot(data, x="clinical", y="gene", color="clinical",
xlab=clinical,
ylab=paste(gene,"expression"),
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()
}