[Tikzdevice-bugs] TikzDevice and ggplot2 panel plots

Lorenzo Isella lorenzo.isella at gmail.com
Sun Jun 13 19:23:33 CEST 2010


Dear All,
I hope this is not too off topic, as I am not reporting a bug but
strictly speaking I am asking how to use tikzDevice+ggplot2 to produce
panel plots.
Consider the small snippet at the end of the email.
I use it quite often to generate panel plots without resorting to
ggplot2 faceting feature. 
Can I combine it with tikzDevice(i.e. I would like to use tikzDevice to
e.g. generate each individual plot or to use it to render the final 2 by
2 panel plot).
Any suggestion is appreciated.
Cheers

Lorenzo



##########################################################
##########################################################
##########################################################

library(ggplot2)

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)
    grid.newpage()
    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))


    dev.off()
} 

data(diamonds)


set.seed(1234)

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) 






More information about the Tikzdevice-bugs mailing list