一、数据处理
install.packages("xlsx")
library(xlsx)
A <- read.csv("/kaggle/input/kegggo/KEGG.csv", header = T)
new_x <- A[c("Pathway.ID","Description","Gene.Count")]
B = read.xlsx("/kaggle/input/kegggo/KEGG-pathway-classification.xlsx",sheetIndex = 1)
AB <- merge(new_x, B, by = "Pathway.ID")
AB <- AB[c("Description.x","Gene.Count","Pathway.Class.1")]
CD <- AB[order(AB$Pathway.Class.1), ]
二、绘柱状图
library(ggplot2)
p <-ggplot(data=CD, aes(x=CD$Description.x, y=CD$Gene.Count, fill=CD$Pathway.Class.1)) +
geom_bar(stat="identity") +
geom_text(aes(label=Gene.Count, y=Gene.Count+0.2),size=3)+
scale_fill_manual(values = c("#FF6666", "#66CCFF", "#99CC33","#66C3A5", "#8DA1CB", "#FD8D62"))+
coord_flip() +
xlab("GO term") +
ylab("Gene_Number") +
labs(title = "The Most Enriched GO Terms")+
facet_grid(Pathway.Class.1~., scale = 'free_y', space = 'free_y')
p
三、保存图片
ggsave("plot.png", plot = p, width = 20, height = 20, dpi = 300)