2020-02-15

富集分析制作气泡图

###自定义作气泡图

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的数据(count)

  GO_DATA=go_data[order(go_data$Count,decreasing = T),]

  GO_DATA=head(GO_DATA,10)


  # 四维数据的展示

  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")

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容