title: Free scales for fill colour with geom_tile in ggplot2
body: <p>I want to set the free scales for x panel using geom_tile and facet_grid in ggplot2 (see the figure below). I used a for loop and print in different viewport to create this figure. </p>
  
  <p>Is there simple method to create the similar figure? </p>
  
  <p>Thanks for any suggestions.</p>
  
  <p>This is the example codes to recreate my figure. </p>
  
  <pre><code>df &lt;- list(x = 1:5, y = 1:5, xp = 1:3, yp = 1:3)
  df &lt;- expand.grid(df)
  df$z &lt;- df$xp * 10 + runif(nrow(df))
  
  library(RColorBrewer)
  cols &lt;- rev(brewer.pal(11, 'RdYlBu'))
  library(ggplot2)
  p &lt;- ggplot(df)
  p &lt;- p + geom_tile(aes(x, y, fill = z))
  p &lt;- p + facet_grid(xp~yp)
  p + scale_fill_gradientn(colours = cols)
  
  
  xp &lt;- unique(df$xp)
  library(grid)
  for (i in seq(along = xp))
  {
      df_i &lt;- df[df$xp == xp[i],]
      p &lt;- ggplot(df_i)
      p &lt;- p + geom_tile(aes(x, y, fill = z))
      p &lt;- p + facet_grid(xp~yp)
      p &lt;- p + scale_fill_gradientn(colours = cols)
      p &lt;- p + theme(
          plot.background = element_rect(fill = 'transparent', colour = 'transparent'),
          strip.background = element_rect(fill = 'transparent', colour = 'transparent'),
          axis.ticks = element_line(colour = 'transparent'))
      p &lt;- p + xlab('') + ylab('')
      if (i &gt; 1)
      {
          p &lt;- p + theme(strip.text.x = element_text(colour = 'transparent'))
      }
      print(p, vp = viewport(0.5, 5/6 - (i - 1) * 0.28, 1, 0.4))
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/XcHFm.png" alt="enter image description here"></p>