R 绘图脚本
rm(list = ls())
library(ggplot2)
windowsFonts(myFont = windowsFont("Times New Roman"))
setwd("D:\\data\\kegg_go_class")
data <- read.table("test.DESeq2.goClass.xls.counts",sep='\t',header = T)
pdf(file="test.DESeq2.goClass.pdf",width=10,height=10)
dorder = factor(as.integer(rownames(data)),labels=data$GO_term) #对数据按GO_term排序
ggplot(data,aes(x=GO_term,y=Number_of_Genes,fill=GO_category)) + #定义X轴,Y轴的数据和颜色填充
geom_bar(stat="identity",position=position_dodge(0.7),width=0.8,aes(x=dorder)) + #定义柱形图的宽度和间距
coord_flip() + #转换横纵坐标
ylim(0,600) +
scale_fill_discrete(name="GO category") + #修改legend的tittle
theme_bw() +
theme(panel.grid =element_blank(),axis.text=element_text(size = 10,face = "bold")) +
geom_text(mapping = aes(label = Number_of_Genes),size = 4,hjust = -0.5) +
ylab("Number of genes") +#修改X轴标签
xlab("")
dev.off()
绘图结果
image.png
测试数据
GO_term GO_category Number_of_Genes
Aging Organismal Systems 42
Excretory system Organismal Systems 46
Environmental adaptation Organismal Systems 72
Sensory system Organismal Systems 78
Circulatory system Organismal Systems 80
Digestive system Organismal Systems 93
Development Organismal Systems 108
Endocrine system Organismal Systems 207
Immune system Organismal Systems 225
Nervous system Organismal Systems 246
Biosynthesis of other secondary metabolites Metabolism 6
Xenobiotics biodegradation and metabolism Metabolism 14
Metabolism of terpenoids and polyketides Metabolism 19
Metabolism of cofactors and vitamins Metabolism 23
Energy metabolism Metabolism 27
Metabolism of other amino acids Metabolism 28
Overview Metabolism 34
Nucleotide metabolism Metabolism 37
Glycan biosynthesis and metabolism Metabolism 40
Amino acid metabolism Metabolism 52
Carbohydrate metabolism Metabolism 56
Lipid metabolism Metabolism 78
Transcription Genetic Information Processing 7
Replication and repair Genetic Information Processing 9
Translation Genetic Information Processing 25
Folding, sorting and degradation Genetic Information Processing 55
Membrane transport Environmental Information Processing 9
Signaling molecules and interaction Environmental Information Processing 229
Signal transduction Environmental Information Processing 517
Cellular community - prokaryotes Cellular Processes 6
Cell motility Cellular Processes 47
Cell growth and death Cellular Processes 146
Cellular community - eukaryotes Cellular Processes 158
Transport and catabolism Cellular Processes 163
网友评论