How to add a autoplot into grid.arrange
1
1
Entering edit mode
9.1 years ago
Kousik ▴ 10

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 • 6.1k views
ADD COMMENT
0
Entering edit mode
3.8 years ago
Ruben ▴ 30

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.

ADD COMMENT

Login before adding your answer.

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