Using DAVID or clusterprofiler for gene enrichment often need to select the pathways that you want to display or arrange the order of pathways. Moreover, the order of clusterprofiler display is sometimes different from the order of input. Therefore, using ggplot can facilitate the realization of bubble charts for enrichment results from various sources.
For example, use clusterprofiler for enrichment
#GeneSymbol is the input gene set 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)
Let's use ggplot to draw a bubble chart. The result looks similar to that drawn by clusterprofiler. The difference lies in the default gene ratio of the x-axis of clusterproliler, and we use count for ggplot, which can be chosen by ourselves. Then we can use ggplot. Level adjusts the order of go terms. For example, go terms with the same number of genes but different pvalues in the top two red boxes conform to the order in the table above in ggplot, while clusterprofiler is the opposite
#goBP is the enrichment result of clusterprofiler, take the first 10 to draw the picture. goinput<-goBP@result[1:10,] head(goinput)
#Make the order of drawing the go term consistent with the input goinput$Description<-factor(goinput$Description,levels = rev(goinput$Description)) #reorderMake the vertical axis sort by go term and 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))