This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Handling manhattan plots in vector graphics editors

Hello all,

I'd like to manually adjust appearance of several manhattan plots generated using ggplot2 and combine them into one nice figure for our paper. The problem is when I try to handle the PDF plots with vector graphics editors, all operations take so much time it is impossible to make any changes in the plots.

Is there any way to simplify the plots so that they can be more easily edited in AI (e.g., merge points from each chromosome into one shape, or sth else)? How do people usually handle manhattan plots during figure editing?

Many thanks for your help :)

snp snp r

Groups are your friend, and masks can occasionally help as well. What edits are you trying to make? What software are you using? Illustrator handles large numbers of objects better than say, Inkscape, so it makes a difference.

The simple fact is that rendering a vector scatterplot is CPU-intensive work. Graphics cards do better with bitmaps (with the associated tradeoff in space and resolution.) So it might help to render vector points down to bitmaps within the PDF. By doing this, you get the benefits of vector graphics for the plot body, and the (significant) performance benefits of bitmap for the data in the plot. See the following for some discussion and code: https://stackoverflow.com/questions/8048984/plot-as-bitmap-in-pdf

Filter out SNPs with pvalue>0.05. This should get rid of about 90% of points. Or stay within R to do plot manipulation to get final merged plot, maybe look into cowplot?

3 answers

3years ago, I wrote a xslt to plot a manhattan plot, for fun.

https://github.com/lindenb/xslt-sandbox/wiki/ManhattanPlot

I've recently found a way of producing moderately-sized Manhattan plots as vector graphics exported to PDF with the R packages sf (for processing spatial data) and ggplot2. As you mentioned, a simplified vector plot should make further editing in a vector graphics editor easier.

My approach is to first convert each point into a circle (a type polygon in geographical software language) and then perform a union of overlapping circles so as to decrease the complexity of the final figure (the large areas made of mostly overlapping points become a single shape for each chromosome).

I've turned this code into an R function that can directly produce these simplified Manhattan plots from a set of summary statistics. It's available on GitHub and the repo also includes a reproducible example (a Manhattan plot of a GWAS of 12M SNPs exported as a PDF file of size 750kB).

If you create the Manhattan plots through geom_point or things like that, there is the ggrastr package, which allows you to produce and save ggplots keeping everything as vector except the points, which are rasterized (I've used it for scatterplots for example).

Edit: googling for "ggraster" + "manhattan" I just found someone doing exactly that approach.

Log in to answer this question.