title: Shared x and y axis labels ggplot2 with ggarrange
body: <p>I have a number off ggplot objects created based off dichotomous count data. I have combined them together using ggarrange. In this function, there is an option to create a shared legend, but as far as I can see no way to create shared x and y axis labels. In addition, the spacing of the figures is very weird - there is a huge gap between the two figure columns, and in addition a large amount of vertical space before the shared legend. So in sum I would like to be able to create shared x and y axes and minimise the unnecessary vertical and horizontal space.</p>
  <p>I checked out the following threads:
  <a href="https://stackoverflow.com/questions/46201091/ggplot2-grid-arrange-shared-legend-share-axis-labels">ggplot2 grid_arrange_shared_legend share axis labels</a></p>
  <p><a href="https://stackoverflow.com/questions/39011020/ggplot-align-plots-together-and-add-common-labels-and-legend">ggplot: align plots together and add common labels and legend</a></p>
  <p><a href="https://stackoverflow.com/questions/57812266/add-common-axis-titles-with-lines-arrows-for-multiple-plots-in-ggplot">Add common axis titles with lines/arrows for multiple plots in ggplot</a></p>
  <p><a href="https://stackoverflow.com/questions/39008773/ggplot-how-to-add-common-x-and-y-labels-to-a-grid-of-plots">ggplot: how to add common x and y labels to a grid of plots</a></p>
  <p>But I think what I want to do is quite a bit simpler, and I don't know how to combine ggarrange with facet.grid which was suggested a few times.</p>
  <p>I have copied a reproducible example below.</p>
  <pre><code>require(tidyverse)
  require(ggpubr)
  require(reshape2) 
  
  condition &lt;- c(&quot;a&quot;, &quot;a&quot;, &quot;a&quot;, &quot;b&quot;, &quot;b&quot;, &quot;b&quot;, &quot;c&quot;, &quot;c&quot;, &quot;c&quot;, &quot;c&quot;)
  binary_1 &lt;- c(0,0,0,0,0,1,1,1,1,1)
  binary_2 &lt;- c(1,1,1,1,1,1,0,0,0,0)
  binary_3 &lt;- c(0,1,1,1,1,1,1,1,0,0)
  binary_4 &lt;- c(1,1,1,0,0,0,0,0,0,0)
  
  
  df &lt;- data.frame(condition, binary_1, binary_2, binary_3, binary_4)
  df
  
  gg_df &lt;- df %&gt;%
    mutate(binary_1 = as.factor(binary_1), binary_2 = as.factor(binary_2), binary_3 = as.factor(binary_3), binary_4 = as.factor(binary_4))
  
  gg_melt &lt;- melt(gg_df)
  
  gg_1 &lt;- ggplot(gg_melt, aes(x=condition, fill = binary_1)) +
    geom_bar(stat=&quot;count&quot;) +
    scale_fill_manual(values = c(&quot;#FDAE61&quot;, &quot;#9E0142&quot;), name = &quot;Behaviour Observed&quot;, labels = c(&quot;0&quot; = &quot;Absent&quot;, &quot;1&quot; = &quot;Present&quot;)) +
    scale_x_discrete(labels = c(a = &quot;Condition A&quot;, b = &quot;Condition B&quot;, c = &quot;Condition C&quot;)) + 
    xlab(&quot;Condition&quot;) + 
    ylab(&quot;Number of Participants&quot;) +
    ggtitle(&quot;Binary 1&quot;) +
    theme(plot.title = element_text(size = 10, face=&quot;bold&quot;, hjust = 0.5)) +
    theme(aspect.ratio = 1) +
    theme(legend.title=element_text(size=10, face = &quot;bold&quot;), axis.title = element_text(size=10, face = &quot;bold&quot;), axis.text = element_text(size=10))+
    theme(legend.box.just = &quot;center&quot;)
  
  gg_2 &lt;- ggplot(gg_melt, aes(x=condition, fill = binary_2)) +
    geom_bar(stat=&quot;count&quot;) +
    scale_fill_manual(values = c(&quot;#FDAE61&quot;, &quot;#9E0142&quot;), name = &quot;Behaviour Observed&quot;, labels = c(&quot;0&quot; = &quot;Absent&quot;, &quot;1&quot; = &quot;Present&quot;)) +
    scale_x_discrete(labels = c(a = &quot;Condition A&quot;, b = &quot;Condition B&quot;, c = &quot;Condition C&quot;)) + 
    xlab(&quot;Condition&quot;) + 
    ylab(&quot;Number of Participants&quot;) +
    ggtitle(&quot;Binary 2&quot;) +
    theme(plot.title = element_text(size = 10, face=&quot;bold&quot;, hjust = 0.5)) +
    theme(aspect.ratio = 1) +
    theme(legend.title=element_text(size=10, face = &quot;bold&quot;), axis.title = element_text(size=10, face = &quot;bold&quot;), axis.text = element_text(size=10))+
    theme(legend.box.just = &quot;center&quot;)
  
  gg_3 &lt;- ggplot(gg_melt, aes(x=condition, fill = binary_3)) +
    geom_bar(stat=&quot;count&quot;) +
    scale_fill_manual(values = c(&quot;#FDAE61&quot;, &quot;#9E0142&quot;), name = &quot;Behaviour Observed&quot;, labels = c(&quot;0&quot; = &quot;Absent&quot;, &quot;1&quot; = &quot;Present&quot;)) +
    scale_x_discrete(labels = c(a = &quot;Condition A&quot;, b = &quot;Condition B&quot;, c = &quot;Condition C&quot;)) + 
    xlab(&quot;Condition&quot;) + 
    ylab(&quot;Number of Participants&quot;) +
    ggtitle(&quot;Binary 3&quot;) +
    theme(plot.title = element_text(size = 10, face=&quot;bold&quot;, hjust = 0.5)) +
    theme(aspect.ratio = 1) +
    theme(legend.title=element_text(size=10, face = &quot;bold&quot;), axis.title = element_text(size=10, face = &quot;bold&quot;), axis.text = element_text(size=10))+
    theme(legend.box.just = &quot;center&quot;)
  
  gg_4 &lt;- ggplot(gg_melt, aes(x=condition, fill = binary_4)) +
    geom_bar(stat=&quot;count&quot;) +
    scale_fill_manual(values = c(&quot;#FDAE61&quot;, &quot;#9E0142&quot;), name = &quot;Behaviour Observed&quot;, labels = c(&quot;0&quot; = &quot;Absent&quot;, &quot;1&quot; = &quot;Present&quot;)) +
    scale_x_discrete(labels = c(a = &quot;Condition A&quot;, b = &quot;Condition B&quot;, c = &quot;Condition C&quot;)) + 
    xlab(&quot;Condition&quot;) + 
    ylab(&quot;Number of Participants&quot;) +
    ggtitle(&quot;Binary 4&quot;) +
    theme(plot.title = element_text(size = 10, face=&quot;bold&quot;, hjust = 0.5)) +
    theme(aspect.ratio = 1) +
    theme(legend.title=element_text(size=10, face = &quot;bold&quot;), axis.title = element_text(size=10, face = &quot;bold&quot;), axis.text = element_text(size=10))+
    theme(legend.box.just = &quot;center&quot;)
  
  figure &lt;- ggarrange(gg_1, gg_2, gg_3, gg_4,
                      labels = NULL,
                      ncol = 2, nrow = 4,
                      common.legend = TRUE, legend = &quot;bottom&quot;,
                      align = &quot;hv&quot;,
                      font.label = list(size = 10, color = &quot;black&quot;, face = &quot;bold&quot;, family = NULL, position = &quot;top&quot;))
  
  pdf(&quot;figure.pdf&quot;)
  figure
  dev.off()
   
  </code></pre>