富集分析制作氣泡圖
###自定義作氣泡圖
x<-read.csv(file.choose(),stringsAsFactors = F)
#篩選p<0.05
x<-x[x$PValue<0.05,]
x_go=x[,1:5]
xbp=x_go[grep("BP",x_go$Category),]
xcc=x_go[grep("CC",x_go$Category),]
xmf=x_go[grep("MF",x_go$Category),]
xkegg=x_go[grep("KEGG",x_go$Category),]
xbp$Term=gsub(".*\\~","",xbp$Term)#Biological Process
xcc$Term=gsub(".*\\~","",xcc$Term)#Cell Component
xmf$Term=gsub(".*\\~","",xmf$Term)#Molecular Function
xkegg$Term=gsub(".*\\:","",xkegg$Term)#KEGG pathway
#加載ggplot2
library(ggplot2)
make_GO_bubble<-function(go_data,term_name){
? #選擇top10的數(shù)據(jù)(count)
? GO_DATA=go_data[order(go_data$Count,decreasing = T),]
? GO_DATA=head(GO_DATA,10)
? # 四維數(shù)據(jù)的展示
? p = ggplot(GO_DATA,aes(X.,Term))
? bubble=p+ geom_point(aes(size=Count,color=-log10(PValue)))
? # 自定義漸變顏色
? bubble =bubble+ scale_colour_gradient(low="green",high="red")
? # 改變圖片的樣式(主題)
? pr=bubble + theme_test(base_size = 16,base_rect_size = 1)
? pr=pr+labs(x="Rich factor",y=term_name,title="Enrichment of DEGs")
? return(pr) }?
#BP
make_GO_bubble(xbp,term_name="Biological Process")#HEIGHT 550
make_GO_bubble(xcc,term_name = "Cell Component")
make_GO_bubble(xmf,term_name = "Molecular Function")
make_GO_bubble(xkegg,term_name = "KEGG pathway")