Question: turning autoplot objects into a grob that can be arranged with grid.arrange
0
gravatar for adeslatt
4.5 years ago by
adeslatt20
United States
adeslatt20 wrote:

Hi there,

I want to arrange several graphical objects side by side -- using say autoplot and barcharts next to them.

Grid.arrange works fine -- but autoplot does not print 

c1 <- ggplot(mtcars, aes(factor(cyl))) + geom_bar()
c2 <- ggplot(mtcars, aes(factor(cyl))) + geom_bar() + coord_flip()
grid.arrange(c1,c2,ncol=1) works great.

Now, looking at the objects that autoplot likes to work with -- usually genomic segments.

set.seed(123)
gr.b <- GRanges(seqnames = "chr1", IRanges(start = seq(1, 100, by = 10),
                  width = sample(4:9, size = 10, replace = TRUE)),
                  score = rnorm(10, 10, 3), value = runif(10, 1, 100))
gr.b2 <- GRanges(seqnames = "chr2", IRanges(start = seq(1, 100, by = 10),
                  width = sample(4:9, size = 10, replace = TRUE)),
                  score = rnorm(10, 10, 3), value = runif(10, 1, 100))
gr.b <- c(gr.b, gr.b2)
p1 <- autoplot(gr.b, geom = "bar")
p2 <- autoplot(gr.b, geom = "bar", aes(fill = value))
t1 <- tracks(default = p1, fill = p2)

t1 will plot it

Tracks then arranges the two genomic centric plots in proportional view in the window.

You can unlist(t1) this If you inspect the autoplot object (which is arranged on a genomic axis typically) you can see that it is a graphical object --   

If you aren't familiar with ggbio  -- it is a very nice package for displaying genomic tracks -- I just want to put some abundance information side by side my transcript information -- just seeing what others do .....

In any case -- thoughts on how I can make a useable grob from the tracks t1 object so I can arrange with grid.arrange?

Anne

grob autoplot R grid.arrange • 1.7k views
ADD COMMENTlink modified 4.5 years ago by RamRS21k • written 4.5 years ago by adeslatt20
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 673 users visited in the last hour