[R] plotting multiple figures on one page

Jim Lemon jim at bitwrit.com.au
Thu Mar 17 08:12:12 CET 2011


On 03/17/2011 07:46 AM, scarlet wrote:
> I am new to the R language. I am trying to plot multiple figures on one page
> through a loop, but the code just produce one graph on one page. Can someone
> show some light on what's wrong?
>
> Here is my code:
>
> library("quantreg")
> tcdata<-read.table("mydata.txt",header=TRUE)
> postscript("myfigure.ps")
> basins<- paste(c("b1","b2","b3","b4","b5","b6"),sep="")
> par(mfrow = c(2,3),mar=c(0,4,0,2),oma=c(5,0,3,0))
>
> for (k in 1:6) {
>
> data0=subset(tcdata,basin==basins[k])
> attach(data0)
>
> model=rq(rain~year,tau=seq(0.1,0.9,0.1))
> plot(summary(model,alpha=0.05,se="iid"),parm=2,pch=19,cex=1.2,mar=c(5,5,5,5),
> ylab=" ",xlab=" ")
>
> }
> dev.off()
>
>
Hi scarlet,
First, you don't really have to paste the values for "basin" together, 
the "c" is all you need. Trying this code:

tcdata<-data.frame(rain=sample(400:1500,360),
  year=rep(1927:1986,each=6),basin=rep(1:6,60))
par(mfrow = c(2,3),mar=c(0,4,0,2),oma=c(5,0,3,0))
for (k in unique(tcdata$basin)) {
  data0=subset(tcdata,basin==k)
  model=rq(rain~year,data=data0,tau=seq(0.1,0.9,0.1))
  plot(summary(model,alpha=0.05,se="iid"),parm=2,pch=19,
   cex=1.2,mar=c(5,5,5,5),ylab=" ",xlab=" ")
}

does exactly what you say, that is, ignores the division of the figure 
area into six parts. As ordinary plots work okay, I assume that there is 
something in the plot method for an rq model that overrides the call to 
par(mfrow...)

Jim



More information about the R-help mailing list