title: Set common y axis limits from a list of ggplots
body: <p>I am running a function that returns a custom ggplot from an input data (it is in fact a plot with several layers on it). I run the function over several different input data and obtain a list of ggplots.</p>
  
  <p>I want to create a grid with these plots to compare them but they all have different y axes.</p>
  
  <p>I guess what I have to do is extract the maximum and minimum y axes limits from the ggplot list and apply those to each plot in the list.</p>
  
  <p>How can I do that? I guess its through the use of ggbuild. Something like this:</p>
  
  <pre><code>test = ggplot_build(plot_list[[1]])
  
  &gt; test$layout$panel_scales_x
  [[1]]
  &lt;ScaleContinuousPosition&gt;
   Range:  
   Limits:    0 --    1
  </code></pre>
  
  <p>I am not familiar with the structure of a ggplot_build and maybe this one in particular is not a standard one as it comes from a "custom" ggplot.</p>
  
  <p>For reference, these plots are created whit the <code>gseaplot2</code> function from the <code>enrichplot</code> package.</p>
  
  <p>I dont know how to "upload" an R object but if that would help, let me know how to do it.</p>
  
  <p>Thanks!</p>
  
  <p><strong>edit after comments (thanks for your suggestions!)</strong></p>
  
  <p>Here is an example of the a <code>gseaplot2</code> plot. GSEA stands for Gene Set Enrichment Analysis, it is a technique used in genomic studies. The <code>gseaplot2</code> function calculates a running average and then plots it and another bar plot on the bottom.</p>
  
  <p><a href="https://i.stack.imgur.com/Xv10S.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Xv10S.png" alt="enter image description here"></a></p>
  
  <p>and here is the grid I create to compare the plots generated from different data:</p>
  
  <p><a href="https://i.stack.imgur.com/kMs68.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kMs68.png" alt="enter image description here"></a></p>
  
  <p>I would like to have a common scale for the "Running Enrichment Score" part.</p>
  
  <p>I guess I could try to recreate the gseaplot2 function and input all of the datasets and then create the grid by facet_wrap, but I was wondering if there was an easy way of extracting parameters from a plot list.</p>
  
  <p>As a reproducible example (from the enrichplot package):</p>
  
  <pre><code>library(clusterProfiler)
  
  data(geneList, package="DOSE")
  gene &lt;- names(geneList)[abs(geneList) &gt; 2]
  wpgmtfile &lt;- system.file("extdata/wikipathways-20180810-gmt-Homo_sapiens.gmt", package="clusterProfiler")
  wp2gene &lt;- read.gmt(wpgmtfile)
  wp2gene &lt;- wp2gene %&gt;% tidyr::separate(term, c("name","version","wpid","org"), "%")
  wpid2gene &lt;- wp2gene %&gt;% dplyr::select(wpid, gene) #TERM2GENE
  wpid2name &lt;- wp2gene %&gt;% dplyr::select(wpid, name) #TERM2NAME
  ewp2 &lt;- GSEA(geneList, TERM2GENE = wpid2gene, TERM2NAME = wpid2name, verbose=FALSE)
  
  gseaplot2(ewp2, geneSetID=1, subplots=1:2)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/KOJ0B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KOJ0B.png" alt="enter image description here"></a></p>
  
  <p>And this is how I generate the plot list (probably there is a much more elegant way):</p>
  
  <pre><code>plot_list = list()
  for(i in 1:3) {
    fig_i = gseaplot2(ewp2, 
              geneSetID=i,
              subplots=1:2)
    plot_list[[i]] = fig_i
  }
  ggarrange(plotlist=plot_list)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/YPYky.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YPYky.png" alt="enter image description here"></a></p>