force a regular plot object into a Grob for use in grid.arrange

后端 未结 1 1966
梦如初夏
梦如初夏 2020-12-11 02:14
b <- ggplot(cars,aes(x=speed,y=dist))+geom_line()
grid.arrange(
    b,
    plot(cars),
    ncol=1
)

gives me the following error

相关标签:
1条回答
  • 2020-12-11 02:59

    you can try with gridGraphics

    library(gridGraphics)
    
    grab_grob <- function(){
      grid.echo()
      grid.grab()
    }
    
    plot(cars)
    g <- grab_grob()
    b <- ggplot(cars,aes(x=speed,y=dist))+geom_line()
    grid.arrange(
      b,g,
      ncol=1
    )
    

    or, alternatively, use gridBase.

    0 讨论(0)
提交回复
热议问题