title: Align multiple plots on x-axis within shiny without merging the plots
body: <p>I have shiny app that has multiple plots with the same x-axis, plots need to be aligned vertically without merging, i.e.: plots must be independent shiny objects from each other. See below reproducible example:</p>
  <pre><code>library(ggplot2)
  library(shiny)
  
  # example data
  df1 &lt;- mtcars
  
  # my custom theme, tried many variants, seems impossible?
  myTheme &lt;- function(){
    theme(legend.position = &quot;none&quot;,
          plot.background = element_rect(fill = &quot;lightblue&quot;),
          axis.text.y = element_text(margin = margin(t = 0, r = 0, b = 0, l = 2, unit = &quot;cm&quot;)),
          axis.title.y = element_text(margin = margin(t = 0, r = 0, b = 0, l = 1, unit = &quot;cm&quot;)),
          plot.margin = unit(c(0, 0, 0, 1), &quot;cm&quot;)
    )}
  
  
  # The App with 2 plots
  runApp(
    shinyApp(
      ui = bootstrapPage(
        plotOutput('plot1', width = 800, height = 200),
        plotOutput('plot2', width = 800, height = 100)
      ),
      server = function(input, output) {
        output$plot1 &lt;- renderPlot({
          ggplot(df1, aes(mpg, gear)) +
            geom_point() +
            coord_cartesian(xlim = c(15, 25)) +
            myTheme()
        })
        output$plot2 &lt;- renderPlot({ 
          ggplot(df1[ df1$gear %in% c(3, 5), ], aes(mpg, gear)) +
            scale_y_continuous(name = &quot;longName&quot;, breaks = c(3, 5), labels = c(&quot;myLongThreeeee&quot;, &quot;My Longggg FIVE&quot;)) +
            geom_area() +
            coord_cartesian(xlim = c(15, 25)) +
            myTheme()
        })
        
      }
    ))
  </code></pre>
  <p><a href="https://i.stack.imgur.com/YrUqH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YrUqH.png" alt="enter image description here" /></a></p>
  <p>I tried to set my own <code>myTheme()</code> with different settings on margin, etc. seems like it is impossible?</p>
  <p>If impossible, not very pretty solution is <a href="https://stackoverflow.com/a/34678561/680068">suggested here</a>, I will just pad Y-tick labels using single width font, something like:</p>
  <pre><code>scale_y_continuous(labels = function(label) sprintf('%15.2f', label)) +
  </code></pre>
  <p>Other alternatives?</p>
  <hr />
  <p><strong>Note:</strong> I am aware of many packages (grid, cowplot, egg, patchwork, etc) that merge plots into one ggplot object and align x-axis, then print. In my case they need to be separate, as user can change some ui settings, and only affected plots should refresh.</p>
  <hr />
  <p><strong>TL;DR</strong>: Is it possible to set fixed size for &quot;axis title&quot; and &quot;axis tick labels&quot; space in centimetres, points, e.g.: 1cm, 4cm?</p>
  <hr />
  <p>Related post about <em>plotly</em>: <a href="https://stackoverflow.com/questions/44341494/shiny-align-plots-axis">Shiny - align plots axis</a></p>