[R] Putting 6 graphs on one page

Dimitri Liakhovitski dimitri.liakhovitski at gmail.com
Fri May 14 19:19:38 CEST 2010


Apologies, if it's a very simple question, but I am really not very
good with trellis.
I have a piece of a code (below) that works just fine and builds 6
graphs - in a loop. I loop through 6 conditions and build one graph
for each.
What would be the most efficient way of creating one page with 6
graphs instead? (2 rows and 3 columns)?
Thanks a lot!
Dimitri

conditions<-c("a","b","c","d","e","f")
conditions.long<-c("It's a","It's b","It's c","It's d","It's e","It's f")

for(i in 1:6) {		
	IV<-conditions[i]
	filename2=paste("DependentVariable ","IV ",IV,".emf",sep="")
	win.metafile(file=filename2)

	out<-as.data.frame(tapply(data$DependentVariable.j,data[[IV]],mean))
	out$IV<-as.factor(as.numeric(row.names(out)))
	names(out)[1]<-"j"
	out2<-as.data.frame(tapply(data$DependentVariable,data[[IV]],mean))
	out<-cbind(out,out2)
	names(out)[3]<-"rf"

	par.settings=trellis.par.set(superpose.line =
list(col=c(PrimaryColors[4],SecondaryColors[4]),lwd = 2,lty=c(1,3)),
      	superpose.symbol = list(cex = 1.5, pch = c(1,3),
lty=c(1,3),col=c(PrimaryColors[4],SecondaryColors[4])),
                reference.line = list(col = "gray", lty ="dotted"))

	plot<-dotplot(c(out$j,out$rf)~rep(out$IV,2),
      	groups=rep(c("Method1","Method1"), each=nrow(out)),
      	type="b",
	scales=list(x=list(cex=1.3),y=list(cex=1.3)),
	auto.key = list(space = "top", points = TRUE, lines = TRUE,cex=1.3),
	ylim=c(0,5),
      	xlab=list(conditions.long[i],cex=1.2,font=2),
	ylab=list("Dependent Variable",cex=1.2,font=2),
	cex.lab=1.5,
      	panel = function(y,x,...) {
           	panel.grid(h = -1, v = -1)
           	panel.xyplot(x, y, ...)
                ltext(x, y, labels=round(y,2), cex=1.3,col="black",font=1,pos=3)
       })
	print(plot)
	dev.off()
}

-- 
Dimitri Liakhovitski
Ninah Consulting
www.ninah.com



More information about the R-help mailing list