This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to save genoPlotR output as a grob

genoPlotR is among few R packages to draw genome alignment plot. I plan to arrange a genome alignment plot with other plots by packages like cowplot. But it seems that the output of plot_gene_map() function can only be exported into a image file. How could I save the output of plot_gene_map() function as a grob?

I have tried code like p1 <- plot_gene_map(...). However, the class of p1 is vpPath. Is it possible to convert a vpPath class to a grob?

genoplotr grob grid

1 answer

Yiwei,

There is no such built-in option, since plot_gene_map produces more complex structures (viewports). But it is definitely possible to arrange gene maps with other plots using plot_gene_map(..., plot_new = FALSE).

There are some examples here: http://genoplotr.r-forge.r-project.org/

But for a quick example:

library(genoPlotR) 
data("three_genes")
gm <- plot_gene_map(dna_segs=dna_segs, comparisons=comparisons, plot_new = FALSE)`
grid_list <- grid.ls(grob=TRUE, viewports=TRUE, print=FALSE) 
grid_list
current.vpTree()

Hope that helps.

Lionel (genoPlotR's maintainer)

Thanks for your quick reply, Prof. Guy!

I just find the grid.grab() function in grid package. I think it is what I am looking for.

library(genoPlotR) 
data("three_genes")
plot_gene_map(dna_segs=dna_segs, comparisons=comparisons)
gb <- grid.grab()
class(gb)
[1] "gTree" "grob"  "gDesc"

Cheers!

Log in to answer this question.