[R] Axis Labels for Compound Plots in ggplot2

Lorenzo Isella lorenzo.isella at gmail.com
Wed Dec 30 12:39:29 CET 2009

Dear All,
I am trying to stitch together multiple plots using ggplot2
Consider for instance the following snippet based on an old thread

vplayout <- function(x, y) viewport(layout.pos.row=x, layout.pos.col=y)

draw4 <- function(pdfname, a,b,c,d,w,h) {

    pdf(pdfname,width=w, height=h)
    pushViewport(viewport(layout=grid.layout(2,2) ) )

        print(a, vp=vplayout(1,1))
        print(b, vp=vplayout(1,2))
        print(c, vp=vplayout(2,1))
        print(d, vp=vplayout(2,2))




randind <- sample(nrow(diamonds),1000,replace=FALSE)
dsmall <- diamonds[randind,]

a <-  qplot(carat, data=dsmall, geom="histogram",binwidth=1)
b <-  qplot(carat, data=dsmall, geom="histogram",binwidth=.1)
c <- qplot(carat, data=dsmall, geom="histogram",binwidth=.01)
d <- qplot(carat, data=dsmall, geom="histogram",binwidth=2)

width <- 7
height <- 7

draw4( "test-4.pdf", a,b,c,d, width, height)

Is there any way to give an overall label along the y and x axis?
E.g.something like a xlab to write some text which applies to the x axis
of all the plots and which should go at the middle bottom of the
compound plot (and something perfectly along these lines for the y axis).
Many thanks


More information about the R-help mailing list