?用DAVID或者clusterprofiler 做基因富集的常常需要挑選一下想展示的通路或者排一下通路的順序,而且,clusterprofiler展示的順序有時(shí)候跟輸入的順序不一樣。因此,用ggplot可以方便對(duì)各種來(lái)源的富集結(jié)果實(shí)現(xiàn)氣泡圖。
如用clusterprofiler做富集
#GeneSymbol為輸入的基因集
toENTREZID = bitr(GeneSymbol,fromType = "SYMBOL",toType = "ENTREZID",OrgDb = "org.Mm.eg.db")
goBP = enrichGO(OrgDb="org.Mm.eg.db",gene = as.vector(toENTREZID$ENTREZID),ont = "BP", pvalueCutoff = 0.05, readable= TRUE)
dotplot(goBP,showCategory=10)+scale_color_gradient(low = "#132B43", high = "#56B1F7")
head(goBP@result)
image
image
我們?cè)儆胓gplot畫(huà)氣泡圖,結(jié)果看起來(lái)和clusterprofiler畫(huà)的差不多,不一樣的地方在于clusterproliler的x軸默認(rèn)的gene ratio,而ggplot我們用的是count,這個(gè)可以自己選擇,再就是ggplot我們可以用level調(diào)節(jié)go term的順序,如最上面兩個(gè)紅框里相同基因數(shù)但是pvalue不同的go term 在ggplot里面符合上面表中的順序,而clusterprofiler是相反的
#goBP為clusterprofiler的富集結(jié)果,取前10個(gè)來(lái)畫(huà)圖。
goinput<-goBP@result[1:10,]
head(goinput)
#使畫(huà)出go term的順序與輸入的一致
goinput$Description<-factor(goinput$Description,levels = rev(goinput$Description))
#reorder使縱軸按照go term 和count排序
?goinput$Description<-factor(goinput$Description,levels = rev(goinput$Description))
ggplot(goinput,aes(x = Count, y =reorder(Description,Count)))+
geom_point(aes(size=Count,color=p.adjust))+
scale_colour_gradient(low="#132B43",high="#56B1F7")+
labs(
color=expression(p.adjust),
size=" Count Number",
x="Gene Count"
)+
theme_bw()+
theme(
axis.text.y = element_text(size = rel(1.8)),
axis.title.x = element_text(size=rel(1.8)),
axis.title.y = element_blank()
)+ scale_size(range=c(5, 10))
?
image