Re: [R] plotting multiple figures on one page

From: Jim Lemon <jim_at_bitwrit.com.au>
Date: Thu, 17 Mar 2011 18:12:12 +1100

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



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 17 Mar 2011 - 07:21:34 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 17 Mar 2011 - 18:10:23 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive