Specifying ggplot2 panel width

后端 未结 1 1924
广开言路
广开言路 2020-12-01 11:19

I have two ggplots on the same page, and I\'d like their panels to be the same width.

Some sample data:

dfr1 <- data.frame(
  time = 1:10,
  value         


        
相关标签:
1条回答
  • 2020-12-01 12:13

    Original solution:

     #   install.packages("ggExtra", repos="http://R-Forge.R-project.org")
     #   library(ggExtra)
     #   align.plots(p1, p2)
    

    Edit (22/03/13):

    Since ggExtra doesn't exist anymore (and many internals of ggplot2 have changed), it's better to use the merging functions (rbind, cbind) provided by the gtable package,

    gl = lapply(list(p1,p2), ggplotGrob)     
    library(gtable)
    g = do.call(rbind, c(gl, size="first"))
    g$widths = do.call(unit.pmax, lapply(gl, "[[", "widths"))
    
    grid.newpage()
    grid.draw(g)    
    

    enter image description here

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