Visualization of Functional Enrichment Result with enrichplot: How to control label size?
1
0
Entering edit mode
@anderstondell-9441
Last seen 4 months ago
Norway

Hi,

Please find reproducable code (and part of my sessioninfo) below, from: https://yulab-smu.github.io/clusterProfiler-book/chapter12.html

I am not able to control the label size in the cnetplot (and in general my other enrichplots are overcrowded with big labels as well). Is there any way to to control the geom_text label size/font size in these plots?

library(DOSE) data(geneList) de <- names(geneList)[abs(geneList) > 2] edo <- enrichDGN(de)

library(enrichplot) barplot(edo, showCategory=20)

edox <- setReadable(edo, 'org.Hs.eg.db', 'ENTREZID') p1 <- cnetplot(edox, foldChange=geneList)

sessionInfo() R version 3.6.1 (2019-07-05) Platform: x8664-w64-mingw32/x64 (64-bit) Running under: Windows Server x64 (build 14393) [31] clusterProfiler3.14.3 msigdbr7.0.1
[33] enrichplot
1.6.1 DOSE_3.12.0

With regards,

clusterProfiler enrichplot cnetplot • 2.6k views
ADD COMMENT
2
Entering edit mode
@james-w-macdonald-5106
Last seen 2 hours ago
United States

Yes, but. The enrichplot package uses ggplot2, which being part of the tidyverse is simultaneously awesome and horrible. So regular R skills don't necessarily apply, because obviously.

Anyway, the gginnards package is useful for hacking away at the smooth, impervious skin that is ggplot2, allowing one to make changes that otherwise might not be simple to do. Using your example (btw, you can highlight the code and click the box that has 10101010 to make it more readable. And carriage returns are your friend... Regurgitating an unformed block of code rather than something readable isn't the way to get people to want to help you.)

> library(DOSE) 
> data(geneList) 
> de <- names(geneList)[abs(geneList) > 2] 
> edo <- enrichDGN(de)
> library(enrichplot)
> edox <- setReadable(edo, 'org.Hs.eg.db', 'ENTREZID') 
> p1 <- cnetplot(edox, foldChange=geneList)

## Don't like the text size?
> library(gginnards)
> library(ggraph)
## find layer classes
> lapply(p1$layers, function(x) class(x$geom))
[[1]]
[1] "GeomEdgePath" "GeomPath"     "Geom"         "ggproto"      "gg"          

[[2]]
[1] "GeomPoint" "Geom"      "ggproto"   "gg"       

[[3]]
[1] "GeomTextRepel" "Geom"          "ggproto"       "gg"  

## we want to 'fix' the GeomTextRepel layer, so delete it first       

> p2 <- delete_layers(p1, "GeomTextRepel")
> p2
## haha I win! Now redo with whatever size you like
> p2 + geom_node_text(size = 2, aes_(label = ~name))
ADD COMMENT
0
Entering edit mode

Very informative; thanks! BTW: you also have to load the library ggraph for the function geom_node_text().

ADD REPLY
0
Entering edit mode

Thanks! I edited to fix.

ADD REPLY
0
Entering edit mode

Thank you, this was to the point, and solves the problem efficiently! There may be some minor problem with positioning the labels still, but I should be able to figure it out, perhaps by reusing the geom_text_repel from the ggrepel package. The following code seems to work fine:

library(gginnards)
library(ggrepel)
p2 <- delete_layers(p1, "GeomTextRepel")
p2<-p2 +geom_text_repel(aes_(x=~x,y=~y,label = ~name), size=2)
p2

I think I'll go for 'awesome' both for tidyverse and your solution, although I do not know how long it would have taken to figure it out on my own. 'aes_' is allready beyond my skill so far.

With regards,

ADD REPLY

Login before adding your answer.

Traffic: 766 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6