[R] problems with saving plots from loop

SonaJ 184544 at mail.muni.cz
Tue May 21 17:57:11 CEST 2013


I cannot find solution for this problem (I was searching on web, but without

I want to plot dose-response models for one concentration and many responses
(lets say 200) and I don´t want to do it manually.

So I use loop for this:

for (i in mydata[,2:201]){                #first column is concentration
pdf(paste("plot_",i,".pdf",sep = ""))    
    ht <- seq(0,5000,1)
    lines(ht, predict(selectedmodel, data.frame(concentration = ht)))       
                                                           #I previously
selected appropriate model for each column within loop
                                                           #(I don´t want to
write here the whole loop with model selection)

This seems, that it works (I obtain many pdf files with plots), but there is
problem with names of these files. R uses random numbers as names , but
after some files (more than 49) one of the selected names is '0' . And after
few other files, there is the same name ('0') again. So the previous file is
overwritten and it is lost. And this is repeated many times (so many plots
are lost). And there is also name '1' doing the same thing...

I really do not know how to solve it...
I also tried

pdf(paste("plot_",names[i],".pdf",sep = ""))    

But it does not help (still random number as names are selected) ...

I would be really happy if someone could help me with this...

Thank you very much,

View this message in context: http://r.789695.n4.nabble.com/problems-with-saving-plots-from-loop-tp4667616.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list