你的lefse图还不清晰吗
2019-12-17 本文已影响0人
Dayueban
起笔:dayueban
责编:王采荷
相信很多人对lefse(LDA Effect Size)分析都不陌生,为微生物组研究领域,主要用于找出组间差异的微生物分类或者功能通路。该分析模块被集合在Galaxy网站。操作起来很方便,但是有一点就是图形导出结果清晰度不是很好,更重要的是,如果标签名很长(有空格)的话,标签名会合并空格,显得很不友好,针对此问题,请教了一些大牛之后,通过R语言软件可以产出和lefse网站分析结果雷同的图形。
准备数据

代码分享
rm(list = ls())
library(RColorBrewer)
kegg <- read.delim("clipboard",header = T, row.names = 1)
label <- factor(kegg$group)
#legend <- unique(Group)
legend <- levels(label)
k <- length(legend)
if (k <= 2){
colors =c("red","blue")
} else if (k <= 9 && k >2) {
colors = brewer.pal(k, "Set1")
} else {
colors = rainbow(k, star=0)
}
which(kegg$group == "RSV")
which(kegg$group == "Ctrl")
fill_colors<-c() #不同的等级,不同的颜色显示
for(i in 1:nrow(kegg)){
if(kegg$group[i]=="RSV"){
fill_colors<-c(fill_colors,"blue")
}
else if(kegg$group[i]=="Ctrl"){
fill_colors<-c(fill_colors,"red")
}
}
tiff("KEGG_L3.tiff",width = 2400,height = 4000, res=300)
#layout(matrix(c(1,2),1,2),widths=c(2,1))
barplot(kegg$score, xlab="LDA SCORE (log 10)",horiz=TRUE,space=0.25,width=0.8,col=fill_colors,names=FALSE,xlim = c(-4,4))
abline(v=c(-4,-3, -2, -1,0,1,2,3,4),col="gray36",lty=2)
class_info <- kegg$group
for (i in 1:nrow(kegg)){
if(class_info[i]=="RSV"){
text(0,i:i-0.4,rownames(kegg[i,]),cex=0.8,offset=0.2,xpd=T,srt=0,pos=2)
}
if(class_info[i]=="Ctrl"){
text(0,i:i-0.4,rownames(kegg[i,]),cex=0.8,offset=0.2,xpd=T,srt=0,pos=4)
}
}
#Y1 = as.data.frame(t(rbind(kegg$logFC,c(array("red",26),array("blue",8)))))
#colnames(Y1) =c("logfc","Group")
#boxplot(Y1$logfc~Y1$Group,Y1,col=c("red","blue"))
legend("topright",legend=legend,pch=15,col=colors,bty="n",cex=1.2)
dev.off()
图形展示
首先,我给出lefse网站给出的图形,大家可以对比一下

看不清楚,我们再放大一些,能看出来哪里不对劲吧

