Issues with scaling down enrichplot's dotplot and gseaplot2 plots
1
0
Entering edit mode
@2e14e879
Last seen 3.3 years ago
Japan

Dear community,

I've been tinkering with enrichplot's dotplot and gseaplot2 for the past few days trying to make GSEA plots for use in a publication. The data is from a RNASeq experiment (mouse) which has been analyzed with DESeq2 to find differentially regulated genes, which were further analyzed with clusterProfiler using GSEA with GO and MSigDB gene sets (great package!). Due to size constraints, I want to specify the dimensions of the plots and export them as svg so that I have some flexibility when putting the figures together in Illustrator.

My issue is that the plots look great in R, but when I export them with ggplot and specify the dimensions, some plot elements, like dots and lines, do not scale down enough.

For example, I created a dotplot of the top 9 GO:BP categories and saved them as svg and png:

p_go <- dotplot(gse, showCategory=9, split=".sign", x="NES", decreasing = TRUE, font.size = 6, label_format = 30) + 
  scale_x_continuous(limit = c(-3, 3), breaks=seq(-3,3,1)) +
  geom_vline(xintercept = 0, linetype="dotted", color = "#444444", size=1) +
   theme( 
    legend.text=element_text(size=5),
    legend.position = "bottom",
    legend.box = "vertical",
    text = element_text(size=6))
p_ggo
ggsave("output/clusterProfiler_dotblot_0.0001_unscaled.svg", width = 12, height = 10, units = "cm")
ggsave("output/clusterProfiler_dotblot_0.0001_unscaled.png", device = agg_png, width = 12, height = 10, units = "cm")

Which gives me (PNG and SVG look the same, so just showing the PNG):

PNG unscaled

The dots are too big for a plot this size. I worked around this by creating the same plot with two times the font size, and then scaling down by 0.5 during export (using ragg):

ggsave("output/clusterProfiler_dotblot_0.0001_scaled.png", width = 12, height = 10, scaling = 0.5, device = agg_png, units = "cm")

PNG scaled

Which is the result I am after, but I'd like to export the plot as svg. Do you know of a way to do this?

Similarly, I performed GSEA with MSigDB sets and used gseaplot2 to visualize the results:

display_geneset <- "IVANOVA_HEMATOPOIESIS_STEM_CELL_LONG_TERM"
p_msig <- gseaplot2(gse_cgp, geneSetID = display_geneset, title = gse_cgp$Description[gse_cgp$ID == display_geneset],
               color = "green", base_size = 5) + theme( aspect.ratio = 1/1.618)

p_msig
ggsave("output/clusterProfiler_GSEA_IVANOVA_small.svg", width=6, units = "cm", scale = 1)

Producing the left image:

gseaplot2

I was able to downscale the lines in Illustrator, ultimately getting what I want (right), but is there a more straightforward and elegant way to do this?

Any help would be greatly appreciated!

sessionInfo( )
R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)

Matrix products: default

locale:
[1] LC_COLLATE=Japanese_Japan.932  LC_CTYPE=Japanese_Japan.932   
[3] LC_MONETARY=Japanese_Japan.932 LC_NUMERIC=C                  
[5] LC_TIME=Japanese_Japan.932    
system code page: 1252

attached base packages:
 [1] parallel  stats4    grid      stats     graphics  grDevices utils     datasets 
 [9] methods   base     

other attached packages:
 [1] org.Mm.eg.db_3.13.0   AnnotationDbi_1.54.1  IRanges_2.26.0        S4Vectors_0.30.0     
 [5] Biobase_2.52.0        BiocGenerics_0.38.0   egg_0.4.5             gridExtra_2.3        
 [9] forcats_0.5.1         stringr_1.4.0         dplyr_1.0.7           purrr_0.3.4          
[13] readr_1.4.0           tidyr_1.1.3           tibble_3.1.2          tidyverse_1.3.1      
[17] extrafont_0.17        ragg_1.1.3            svglite_2.0.0         msigdbr_7.4.1        
[21] ggridges_0.5.3        DOSE_3.18.1           ggplot2_3.3.5         enrichplot_1.12.2    
[25] clusterProfiler_4.0.2
RNASeq clusterProfiler enrichplot • 5.4k views
ADD COMMENT
0
Entering edit mode

dotplot() + scale_size(range = c(1,5) should work

ADD REPLY
0
Entering edit mode
@james-w-macdonald-5106
Last seen 2 days ago
United States

If I just use the default for either ggsave or svg I get pretty much what you have after processing through illustrator.

enter image description here

ADD COMMENT
1
Entering edit mode

Or if you want it narrow and wide, you can save it with the correct width instead of what you have done, which seems to be a 6cm wide by 17.8 cm high image that you have to rescale? For example, using png("whatevs.png", 480, 240) I get

enter image description here

ADD REPLY
0
Entering edit mode

Thanks for your comment James! I actually forgot to add a line defining the aspect ratio of the plot, that's probably why it came out with the strange dimensions. I edited the code in the original post.

I could recreate the plot you generated with my data using the standard png function as you described. However, since the standard resolution is 72 ppi the plot turns out pretty big when I import it into AI. (480/72 = 6.7 in), so I'd have to rescale. png default

Defining the dimensions in cm gets me this:

png("output/whatevs_300ppi_6x3.7.png", width = 6, height = 3.7, units = "cm", res = 300)
p
dev.off()

png 6cm Like the svg I posted earlier.

I did manage to scale down the output with the ragg scaling function (had to scale up the font size accordingly):

agg_png("output/whatevs_1200ppi_base_20_png-agg_scale-0.25.png", width = 6, height = 3.7, units = "cm", res = 1200, scaling = 0.25)

png scaled

This opens as 6 cm width in AI, so that would work.

I was hoping to export in svg, but I can't use ragg's scaling for svgs. Apparently svglite can scale outputs, I'll have a look at it later.

ADD REPLY

Login before adding your answer.

Traffic: 512 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