How to arrange plots in a single column using grid_arrange_shared_legend

Viewed 343

I've been attempting to use the grid_arrange_shared_legend code to create a column of ggplot2 plots with a single legend (I can't use straight faceting because I need to use coord_flip and have different x-axis sizes - this has been documented by Hadley as not working - https://github.com/hadley/ggplot2/issues/95)

The code prints out the 4 plots as a 2x2 matrix with the legend underneath (see http://rpubs.com/sjackman/grid_arrange_shared_legend).

I have been trying to get the 4 plots plus legend in a single column, but failed miserably. Oddly enough, I assumed that the ncol=1 argument to grid.arrange would make it all a single column but it doesn't.

At present, given 4 graphs plus a legend, the code gives this layout:

+-----------+      +-----------+
|           |      |           |
|     1     |      |    3      |
|           |      |           |
+-----------+      +-----------+

+-----------+      +-----------+
|           |      |           |
|     2     |      |    4      |
|           |      |           |
+-----------+      +-----------+


        LEGEND HERE

I'm trying to get

+-----------+    
|           |   
|     1     |   
|           |    
+-----------+ 

+-----------+ 
|           |  
|     2     |  
|           |  
+-----------+ 

+-----------+    
|           |   
|     3     |   
|           |    
+-----------+ 

+-----------+ 
|           |  
|     4     |  
|           |  
+-----------+ 

 LEGEND HERE

Any help appreciated. Regards Pete

1 Answers
Related