Hi, I am trying to generate a group of graphics with an iteration. Some thing like this... x=1 y=1 max=10 myfiles <- paste("foo", x:max, ".png", sep="") while (x =< max) { png(file=myfiles, pointsize = 20, width = 600, height = 600, units = "px", bg="#eaedd5") plot(x,y) dev.off() x=x+1 y=y+1 } I am getting only one *.png file with the name of the first position in myfiles and the content of the last graphic in the iteration. Please, could you tell me if it is possible to iterate file= in any other way? Thanks! Ricardo -- Ricardo Rodr?guez Your XEN ICT Team
How about this: x <- 1 y <- 1 mmax <- 10 my.files <- paste("foo", x:mmax, ".png", sep="") for (i in my.files) { png(filename=i, pointsize=20, width=600, height=600, units="px", bg="#eaedd5") plot(x, y) dev.off() x <- x+1 y <- y+1 } Normally I would avoid for loops, but I think this application is a legitimate use. Cheers, Simon. On Fri, 2008-04-18 at 03:05 +0200, [Ricardo Rodriguez] Your XEN ICT Team wrote:> Hi, > > I am trying to generate a group of graphics with an iteration. Some > thing like this... > > x=1 > y=1 > max=10 > myfiles <- paste("foo", x:max, ".png", sep="") > while (x =< max) > { > png(file=myfiles, pointsize = 20, width = 600, height = 600, > units = "px", bg="#eaedd5") > plot(x,y) > dev.off() > x=x+1 > y=y+1 > } > > I am getting only one *.png file with the name of the first position in > myfiles and the content of the last graphic in the iteration. Please, > could you tell me if it is possible to iterate file= in any other way? > > Thanks! > > Ricardo > >-- Simon Blomberg, BSc (Hons), PhD, MAppStat. Lecturer and Consultant Statistician Faculty of Biological and Chemical Sciences The University of Queensland St. Lucia Queensland 4072 Australia Room 320 Goddard Building (8) T: +61 7 3365 2506 http://www.uq.edu.au/~uqsblomb email: S.Blomberg1_at_uq.edu.au Policies: 1. I will NOT analyse your data for you. 2. Your deadline is your problem. The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. - John Tukey.
Hi, Simon Blomberg wrote:> How about this: > > x <- 1 > y <- 1 > mmax <- 10 > > my.files <- paste("foo", x:mmax, ".png", sep="") > > for (i in my.files) { > png(filename=i, pointsize=20, width=600, height=600, units="px", > bg="#eaedd5") > plot(x, y) > dev.off() > x <- x+1 > y <- y+1 > } >It does the trick! Thanks.> Normally I would avoid for loops, but I think this application is a > legitimate use.Please, why do you avoid looping normally? Thanks again. Greetings, Ricardo -- Ricardo Rodr?guez Your XEN ICT Team
On Thu, Apr 17, 2008 at 8:05 PM, [Ricardo Rodriguez] Your XEN ICT Team <webmaster at xen.net> wrote:> Hi, > > I am trying to generate a group of graphics with an iteration. Some > thing like this... > > x=1 > y=1 > max=10 > myfiles <- paste("foo", x:max, ".png", sep="") > while (x =< max) > { > png(file=myfiles, pointsize = 20, width = 600, height = 600, > units = "px", bg="#eaedd5") > plot(x,y) > dev.off() > x=x+1 > y=y+1 > } > > I am getting only one *.png file with the name of the first position in > myfiles and the content of the last graphic in the iteration. Please, > could you tell me if it is possible to iterate file= in any other way?Have you looked at ?png : filename: the name of the output file. The page number is substituted if a C integer format is included in the character string, as in the default. (The result must be less than 'PATH_MAX' characters long, and may be truncated if not. See 'postscript' for further details.) Tilde expansion is performed where supported by the platform. so the default filename ("Rplot%03d.jpeg") already does what you want. Hadley -- http://had.co.nz/
Hi Richard, thanks for your input! Richard Rowe wrote:> which figures if you look at what you are doing line by line ... try it > > > try something like: > > max=10 > > for (i in 1:max){ > myfiles <- paste("foo", i, ".png", sep="") # generates names > foo1.png, foo2.png, etc > png(file=myfiles, pointsize = 20, width = 600, height = 600, units = > "px", bg="#eaedd5") > plot(x[i,],y[i,]) # > !!!!you will need to change what you are plotting to something like > this!!!! > dev.off() } >There are at least two things I don't understand in your proposal: 1. How x and y variate? I mean, there is not x= or y= commands prior to enter for(). 2. Whatever I set or not x and y, the code claims: Error in x[i, ] : incorrect number of dimensions Please, why to you use plot(x[i,],y[i,]) instead of plot(x,y)? Thanks for your help, Ricardo -- Ricardo Rodr?guez Your XEN ICT Team
Mark, Mark Leeds wrote:> Oh, I'm sorry that didn't work. If you have time, can you resend it to me if > you still have it ( I don't ) cause I'd like to see why. Thanks.My fault! It does work! I've tried it this morning quickly, before leaving my SOHO, and it seems I was making any mistake. It does perfectly works as here... x=1 y=1 max=10 myfiles <- paste("foo", x:max, ".png", sep="") while (x =< max) { png(file=myfiles[x], pointsize = 20, width = 600, height = 600, units = "px", bg="#eaedd5") plot(x,y) dev.off() x=x+1 y=y+1 } Thank you so much for your help and sorry for the noise! Cheers, Ricardo -- Ricardo Rodr?guez Your XEN ICT Team