Thanks Uwe . The parentheses were a typo. Please note that if I have only 9
subjects in my data then the following works (creates 493 KB data file)



#windows()

{tiff(file=paste("Outfile",1,".tiff",sep=""),width=17.15

      ,height=17.15,units="cm", res=1200, pointsize=10, compression =
"lzw")}

par(mar=c(5,5,4,1),mfrow=c(3,3))

for(i in 1:9){

   dt1 = dat[dat$ID==i,]

   #pagei=as.integer(ceiling(i/9))

   #This does not work

   #if(i==1) {tiff(file=paste("Outfile",pagei,".tiff",sep=""),width=17.15

   ##,height=17.15,units="cm", res=1200, pointsize=10, compression = "lzw")}


   #par(mar=c(5,5,4,1),mfrow=c(3,3))

   plot(dt1[, "IDV"],dt1[, "DV"], type="n",ylim=range(dt1[, "DV"]),
xlim=range(dt1[, "IDV"]))

   lines(dt1[, "IDV"], dt1[, "DV"], type="b", col=1,lwd=3,pch=1)

   title(paste(i),col=8,cex=.8)

   #if(i==5) dev.off ## close file

   ## open new file

   #if(i==5) {tiff(file=paste("Outfile",pagei,".tiff",sep=""),width=17.15

   ##,height=17.15,units="cm", res=1200, pointsize=10, compression = "lzw")}

   #if(i==9) dev.off () ## close file

   #if(i==9) {tiff(file=paste("Outfile",pagei,".tiff",sep=""),width=17.15

   ##,height=17.15,units="cm", res=1200, pointsize=10, compression = "lzw")}

}

dev.off()





My workaround around was to break the dataset into small data each with 9
subjects but if I change the mfrow then I have to change no. of subjects.
Any smart suggestion to get around this? I tried to open and close devices
based on iterations (i) but it does not work for me




2011/5/10 Uwe Ligges <lig...@statistik.tu-dortmund.de>

>
>
> On 10.05.2011 03:36, John S wrote:
>
>> Dear Friends,
>>
>> I have been trying to save multiple 3x3 (mfrow=c(3,3) graphics inside a
>> loop
>> using tiff figure format (not using PDF or savePlot functions) with no
>> success. Could you please help?
>>
>> Here is a simplified example code:
>>
>>
>>
>> dat=data.frame (ID=rep(1:10,each=10),IDV=rep(seq(1:10),times=10))
>>
>> dat$DV<- with(dat, 50+15*IDV)
>>
>> dat=dat[order(dat$ID,dat$IDV),]
>>
>> for(i in 1:10){
>>
>>    dt1 = dat[dat$ID==i,]
>>
>>    pagei=as.integer(ceiling(i/9))
>>
>>    #This does not work
>>
>>    if(i==1) {tiff(file=paste("Outfile",pagei,".tiff",sep="")
>>
>>      ,width=17.15,height=17.15,units="cm", res=1200, pointsize=10,
>> compression = "lzw")}
>>
>
> You may not be able to allocate space for this huge tiffs (at least I am
> not able to do so under Windows).
>
>
>
>
>   if(i==10) {tiff(file=paste("Outfile",pagei,".tiff",sep="")
>>
>>      ,width=17.15,height=17.15,units="cm", res=1200, pointsize=10,
>> compression = "lzw")}
>>
>>    par(mar=c(5,5,4,1),mfrow=c(3,3))
>>
>>    plot(dt1[, "IDV"],dt1[, "DV"], type="n")
>>
>>    lines(dt1[, "IDV"], dt1[, "DV"], type="b", col=1,lwd=3,pch=1)
>>
>>    title(paste(i),col=8,cex=.8)
>>
>>  if(i==9) dev.off ## close file
>>
>
> Your forgot parentheses after dev.off.
>
> Uwe Ligges
>
>
>  }
>>
>> dev.off()
>>
>>  The idea is to save 2 files with 3x3 layouts but I only get one subject
>> in
>> Outfile1.
>>
>>
>>
>> OS: Windows 7 64 bits
>>
>> R version 2.13.0
>>
>> Many Thanks,
>>
>> John
>>
>>        [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help@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<http://www.r-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to