Search code examples
rggplot2ggplotly

grid.arrange with ggplotly


I was wondering if there is a workaround to get the layout of the plots that we get using grid.arrange using ggplotly.

The resulting object from grid.draw is not a ggplot object obviously. So, wondering for any workarounds to pass the following plot to ggplotly.

library(ggplot2)
library(gridExtra)

p1 = qplot(1:20,1:20)
p2 = qplot(1:20, 20:1)

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

Solution

  • Maybe this is what you are looking for:

    library(ggplot2)
    library(gridExtra)
    library(plotly)
    
    p1 = qplot(1:20,1:20)
    p2 = qplot(1:20, 20:1)
    
    ply1 <- ggplotly(p1)
    ply2 <- ggplotly(p2)
    
    subplot(ply1, ply2, nrows=1)