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)
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))
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:
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.
Very informative; thanks! BTW: you also have to load the library
ggraph
for the functiongeom_node_text()
.Thanks! I edited to fix.
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 theggrepel
package. The following code seems to work fine: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,