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) #對數(shù)據(jù)按GO_term排序
ggplot(data,aes(x=GO_term,y=Number_of_Genes,fill=GO_category)) + #定義X軸调塌,Y軸的數(shù)據(jù)和顏色填充
geom_bar(stat="identity",position=position_dodge(0.7),width=0.8,aes(x=dorder)) + #定義柱形圖的寬度和間距
coord_flip() + #轉(zhuǎn)換橫縱坐標(biāo)
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軸標(biāo)簽
xlab("")
dev.off()
繪圖結(jié)果
image.png
測試數(shù)據(jù)
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