title: R, ggplot - Graphs sharing the same y-axis but with different x-axis scales
body: <h1>Context</h1>
  
  <p>I have some datasets/variables and I want to plot them, but I want to do this in a compact way. To do this I want them to share the same y-axis but distinct x-axis and, because of the different distributions, I want one of the x-axis to be log scaled and the other linear scaled.</p>
  
  <h1>Example</h1>
  
  <p>Suppose I have a long tailed variable (that I want the x-axis to be log-scaled when plotted):</p>
  
  <pre><code>library(PtProcess)
  library(ggplot2)
  
  set.seed(1)
  lambda &lt;- 1.5
  a &lt;- 1
  pareto &lt;- rpareto(1000,lambda=lambda,a=a)
  x_pareto &lt;- seq(from=min(pareto),to=max(pareto),length=1000)
  y_pareto &lt;- 1-ppareto(x_pareto,lambda,a)
  df1 &lt;- data.frame(x=x_pareto,cdf=y_pareto)
  
  ggplot(df1,aes(x=x,y=cdf)) + geom_line() + scale_x_log10()
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/r23UV.png" alt="Long tail"></p>
  
  <p>And a normal variable:</p>
  
  <pre><code>set.seed(1)
  mean &lt;- 3
  norm &lt;- rnorm(1000,mean=mean)
  x_norm &lt;- seq(from=min(norm),to=max(norm),length=1000)
  y_norm &lt;- pnorm(x_norm,mean=mean)
  df2 &lt;- data.frame(x=x_norm,cdf=y_norm)
  
  ggplot(df2,aes(x=x,y=cdf)) + geom_line()
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/FBrYM.png" alt="Normal"></p>
  
  <p>I want to plot them side by side using the same y-axis. </p>
  
  <h2>Attempt #1</h2>
  
  <p>I can do this with facets, which looks great, but I don't know how to make each x-axis with a different scale (<code>scale_x_log10()</code> makes both of them log scaled):</p>
  
  <pre><code>df1 &lt;- cbind(df1,"pareto")
  colnames(df1)[3] &lt;- 'var'
  df2 &lt;- cbind(df2,"norm")
  colnames(df2)[3] &lt;- 'var'
  df &lt;- rbind(df1,df2)
  
  ggplot(df,aes(x=x,y=cdf)) + geom_line() + 
         facet_wrap(~var,scales="free_x") + scale_x_log10()
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/DVVpd.png" alt="Facets attempt"></p>
  
  <h2>Attempt #2</h2>
  
  <p>Use <code>grid.arrange</code>, but I don't know how to keep both plot areas with the same aspect ratio:</p>
  
  <pre><code>library(gridExtra)
  p1 &lt;- ggplot(df1,aes(x=x,y=cdf)) + geom_line() + scale_x_log10() +
        theme(plot.margin = unit(c(0,0,0,0), "lines"),
              plot.background = element_blank()) +
        ggtitle("pareto")
  p2 &lt;- ggplot(df2,aes(x=x,y=cdf)) + geom_line() + 
        theme(axis.text.y = element_blank(), 
              axis.ticks.y = element_blank(), 
              axis.title.y = element_blank(),
              plot.margin = unit(c(0,0,0,0), "lines"),
              plot.background = element_blank()) +
        ggtitle("norm")
  grid.arrange(p1,p2,ncol=2)
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/5SYOd.png" alt="Grid attempt"></p>
  
  <p><strong>PS: The number of plots may vary so I'm not looking for an answer specifically for 2 plots</strong></p>