gg_share_legend <- function(...) {
## AKA  grid_arrange_shared_legend() from: 
##  https://github.com/hadley/ggplot2/wiki/Share-a-legend-between-two-ggplot2-graphs

    plots <- list(...)
    g <- ggplotGrob(plots[[1]] + theme(legend.position="bottom"))$grobs
    legend <- g[[which(sapply(g, function(x) x$name) == "guide-box")]]
    lheight <- sum(legend$height)
    grid.arrange(
        do.call(arrangeGrob, lapply(plots, function(x)
            x + theme(legend.position="none"))),
        legend,
        ncol = 1,
        heights = unit.c(unit(1, "npc") - lheight, lheight))
}


## EXAMPLE:
if (FALSE) {
    dsamp <- diamonds[sample(nrow(diamonds), 1000), ]
    p1 <- qplot(carat, price, data=dsamp, colour=clarity)
    p2 <- qplot(cut, price, data=dsamp, colour=clarity)
    p3 <- qplot(color, price, data=dsamp, colour=clarity)
    p4 <- qplot(depth, price, data=dsamp, colour=clarity)
    grid_arrange_shared_legend(p1, p2, p3, p4)
}
