This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to add a autoplot into grid.arrange

Hi,

I am facing difficulties to add an autoplot into grid.arrange. Please go through below mentioned code:

library(ggplot2)
library(grid)
library(gridExtra)

library(ggbio)
library(Homo.sapiens)

p1 <- ggplot(df1, aes(x=Start, y=Log2RPM, group=Genotype)) +
geom_line(aes(colour = Genotype), size=1) +
facet_grid(Tag ~ .)

gene <- GRanges("chr10", IRanges(81035775, 81047732))

p2<- autoplot(Homo.sapiens, which = gene)

grid.arrange(p1, p2, nrow = 2 )

Error:

Error in gList(list(grobs = list(list(x = 0.5, y = 0.5, width = 1, height = 1,  :
  only 'grobs' allowed in "gList"
In addition: Warning message:
In class(grob) <- c("gTableChild", class(grob)) :
  Setting class(x) to multiple strings ("gTableChild", "GGbio", ...); result will no longer be an S4 object

Any help will be appreciated.

-Kousik

ggplot2

1 answer

This is a long while ago but hasn't received any answers yet. I had a similar issue and found that this often occurs when you try and mix two types of plots. In this case, the autoplot and a ggplot2. I imagine ggplot is compatible with grid.arrange not the autoplot. You could also do it using the native functions to plot two figures or transform you autoplot to a ggplot by exporting its data some how.

Log in to answer this question.