I'm using the commonly referenced g_legend function to pull a legend out of a graph made with ggplot2 such that I can organize it with multiple plots using grid.arrange. I want the legend to be a single row of elements such that I can easily put it at the bottom of my grid. However, regardless of format on the original plot, g_legend always returns a legend with a single column. Does anyone know of a way to force the legend to only have a single row?
#extract legend
#https://github.com/hadley/ggplot2/wiki/Share-a-legend-between-two-ggplot2-graphs
g_legend<-function(a.gplot){
tmp <- ggplot_gtable(ggplot_build(a.gplot))
leg <- which(sapply(tmp$grobs, function(x) x$name) == "guide-box")
legend <- tmp$grobs[[leg]]
return(legend)}