2
$\begingroup$

I am curious how people make genome track plots such as what can be done with the Bioconductor package ggbio.

For example this plot was made w/ ggbio: enter image description here

I think ggbio is great for making fast plots, but it is kind of a pain to make publication quality figures because it is hard to manipulate the plots after they are constructed. Normally I would use ggplot2 to customize the plot extensively, but it doesn't work very well after plotting with ggbio.

How can I use ggbio for these types of plots? Is there a better tool instead?

EDIT: I would get the legends for each individual plot and combine them before adding back to the main plot using something like this:

leg1.grob = cowplot::get_legend(plot1)
leg2.grob = cowplot::get_legend(plot2)
sharedleg.grob = gridExtra::gtable_rbind(leg1,leg2)

mainplot.grob = ggplotGrob(main_plot)
mainplot.grob = gtable_add_cols(mainplot.grob, 
                                widths = sum(sharedleg.grob$widths))
mainplot.grob = gtable_add_grobs(mainplot.grob, 
                                 grobs = sharedleg.grob, 
                                 t=t,b=b,l=l,r=r)
cowplot::ggdraw(mainplot.grob)
$\endgroup$
  • 1
    $\begingroup$ Could you expand on "hard to manipulate the plots". What is the expected output? I mainly use ggbio for gene track and to merge multiple plots vertically, x-axis aligned. $\endgroup$ – zx8754 May 21 '18 at 9:35
  • $\begingroup$ The "hard to manipulate" part is that ggbio constructed plots do not return a ggplot or gtable object. I can access the grobs from a ggbio tracks object, but they won't be aligned as they would be in the final plot. I like to make shared legends and include them in the plot, and without having a gtable or ggplot object it is hard to add the shared legends in, and I end up having to save them as a separate file which is tedious. EDIT: FYI I mainly use ggbio for the same purposes as you - gene tracks + x-axis alignment $\endgroup$ – Reilstein May 21 '18 at 18:25
  • $\begingroup$ So the question is: how do we make ggbio shared legend? At the moment I use custom/manual legends like you are doing. $\endgroup$ – zx8754 May 21 '18 at 18:54
  • 1
    $\begingroup$ I added the process I would use to create the shared legend, is that what you mean? $\endgroup$ – Reilstein May 21 '18 at 19:15
  • 1
    $\begingroup$ I like gviz bioconductor.org/packages/release/bioc/html/Gviz.html $\endgroup$ – Chris_Rands May 23 '18 at 8:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.