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() -- View this message in context: r.789695.n4.nabble.com/plotting-multiple-figures-on-one-page-tp3382981p3382981.html Sent from the R help mailing list archive at Nabble.com.
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
Jim, Thanks for looking into this. The c without paste works. If the rq model overrides the mfrow, I think I will have to piece together individual plots using other software. scarlet -- View this message in context: r.789695.n4.nabble.com/plotting-multiple-figures-on-one-page-tp3382981p3384787.html Sent from the R help mailing list archive at Nabble.com.
Scarlet, If the mfrow is being overridden, perhaps the rimage package might be able to piece the individual plots... -- Muhammad Rahiz Researcher & DPhil Candidate (Climate Systems & Policy) School of Geography & the Environment University of Oxford On Thu, 17 Mar 2011, scarlet wrote:> Jim, > > Thanks for looking into this. The c without paste works. If the rq model > overrides the mfrow, I think I will have to piece together individual plots > using other software. > > scarlet > > -- > View this message in context: r.789695.n4.nabble.com/plotting-multiple-figures-on-one-page-tp3382981p3384787.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
scarlet wrote: > > Jim, > > Thanks for looking into this. The c without paste works. If the rq > model overrides the mfrow, I think I will have to piece together > individual plots using other software. I had a look at the plot.summary.rqs function and it does work out its own mfrow value and then restore the original value on exit. Jim