我的数据:
一组差异表达分析结果,包括基因的名称,基因的表达量已经差异分析结果,上下调信息如下,所以我只需要第一列可以做venn图,最后一列做数量统计:
当然我的差异表达分组很多,有很多这样的文件,不同的组合比较,我需要批量的用R读入数据,然后统计分组中差异表达基因的数目,并绘制柱状图;
R语言代码:
library(reshape2)
local({r <- getOption("repos") ;r["CRAN"] <- "http://mirrors.tuna.tsinghua.edu.cn/CRAN/" ;options(repos=r)})
library(ggplot2)
library(cowplot)
library(RColorBrewer)
library(Vennerable)
brewer.pal(7,"Set1")
display.brewer.all()
setwd("D:/BaiduNetdiskDownload/report/6.DEG_Analysis/")
getwd()
#########################################################################
#批量读入相同后缀的文本文件,并且只截取第一列和最后一列
files=list.files("./",pattern = "*DEG\\.final.txt",recursive = T)
data=lapply(files,function(fl){d=read.table(fl,header=TRUE,comment.char="",sep = "\t",check.names=FALSE)[,c(1,18)]})
#将数据整理成表格mydata
mydata=sapply(data,function(d){table(d[,2])})
colnames(mydata)<-c("DAF2 vs GDAF2","DAF5 vs GDAF5","DAF11 vs GDAF11","DAF16 vs GDAF16")
mydata=as.data.frame(melt(mydata))
p<-ggplot(mydata,aes(x = factor(Var2,levels = c("DAF2 vs GDAF2","DAF5 vs GDAF5","DAF11 vs GDAF11","DAF16 vs GDAF16"),ordered=T),
y = value,
fill=factor(Var1,levels=c("up","down"),ordered = T)))+
geom_bar(stat = "identity" ,width=0.5,position=position_dodge(width = 0.6))+
geom_text(aes(label=value),position=position_dodge(width = 0.6),size = 4,vjust = -0.25)+
scale_fill_manual(values=c( "#E41A1C", "#377EB8", "#4DAF4A"))+
theme(legend.key = element_blank(),legend.title = element_blank(),
axis.text.x = element_text(angle=60, vjust=0.5,hjust=0.5)
)+ xlab("")+ylab("Number of DEGs")
#输出图片
pdf(file="DEGNum.pdf", height=7, width=7)
print(p)
dev.off()
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!