hello list! I'm sorry, I just stumbled over this strange behaviour (at least I am not able to explain the behaviour, therefore I assume it to be a strange behaviour): attach(water) # I know, this is not recommended names(water[3:10]) [1] "temp" "pH" "DO" "BOD" "COD" "no3" "no2" "po4" for (i in names(water)[3:10]){ fname<-paste("Henni/GFX/fem",i,".png",sep="") mname<-paste("Henni/GFX/mal",i,".png",sep="") png(fname,1000,1000) xyplot(N_female~eval(parse(text=i)) |group,xlab=i,ylab="Abundance") graphics.off() png(mname,1000,1000) xyplot(N_male~eval(parse(text=i)) |group,xlab=i,ylab="Abundance") graphics.off() } well, to anyone's surprise, there are no plots in the folder. the loop finishes (i, fname and mname have values assigned) and executing png(fname,1000,1000) xyplot(N_female~eval(parse(text=i)) |group,xlab=i,ylab="Abundance") graphics.off() does produce a png in the folder. I assume this to be caused by the png function, since removing the graphics.off() and playing with dev.off() and the likes did not help. anyone ideas?? am I missing the obvious??
Hi, I myself do not use lattice plots, but I think your problem is in FAQ 7.22: you didn't print() your plots. See the R FAQ for more details on it. HTH, Ivan Le 3/7/2011 18:28, Sacha Viquerat a ?crit :> hello list! I'm sorry, I just stumbled over this strange behaviour (at > least I am not able to explain the behaviour, therefore I assume it to > be a strange behaviour): > > attach(water) # I know, this is not recommended > > names(water[3:10]) > [1] "temp" "pH" "DO" "BOD" "COD" "no3" "no2" "po4" > > for (i in names(water)[3:10]){ > fname<-paste("Henni/GFX/fem",i,".png",sep="") > mname<-paste("Henni/GFX/mal",i,".png",sep="") > png(fname,1000,1000) > xyplot(N_female~eval(parse(text=i)) |group,xlab=i,ylab="Abundance") > graphics.off() > png(mname,1000,1000) > xyplot(N_male~eval(parse(text=i)) |group,xlab=i,ylab="Abundance") > graphics.off() > } > > well, to anyone's surprise, there are no plots in the folder. the loop > finishes (i, fname and mname have values assigned) and executing > > png(fname,1000,1000) > xyplot(N_female~eval(parse(text=i)) |group,xlab=i,ylab="Abundance") > graphics.off() > > does produce a png in the folder. I assume this to be caused by the > png function, since removing the graphics.off() and playing with > dev.off() and the likes did not help. anyone ideas?? am I missing the > obvious?? > > ______________________________________________ > 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. >-- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. S?ugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calandra at uni-hamburg.de ********** for771.uni-bonn.de webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php
Try: print(xyplot(N_female~eval(parse(text=i)) |group,xlab=i,ylab="Abundance")) Steve Riley, PharmD, PhD Clinical Pharmacology Specialty Care Medicines Development Group Pfizer Inc. 50 Pequot Ave MS-6025-B2110 New London, CT 06320 Email: steve.riley at pfizer.com Phone: (860) 732-1796>>-----Original Message----- >>From: r-help-bounces at r-project.org[mailto:r-help-bounces at r-project.org]>>On Behalf Of Sacha Viquerat >>Sent: Monday, March 07, 2011 12:28 PM >>To: r-help at r-project.org >>Subject: [R] png inside loop >> >>hello list! I'm sorry, I just stumbled over this strange behaviour (at >>least I am not able to explain the behaviour, therefore I assume it to >>be a strange behaviour): >> >>attach(water) # I know, this is not recommended >> >>names(water[3:10]) >>[1] "temp" "pH" "DO" "BOD" "COD" "no3" "no2" "po4" >> >>for (i in names(water)[3:10]){ >> fname<-paste("Henni/GFX/fem",i,".png",sep="") >> mname<-paste("Henni/GFX/mal",i,".png",sep="") >> png(fname,1000,1000) >> xyplot(N_female~eval(parse(text=i))|group,xlab=i,ylab="Abundance")>> graphics.off() >> png(mname,1000,1000) >> xyplot(N_male~eval(parse(text=i)) |group,xlab=i,ylab="Abundance") >> graphics.off() >>} >> >>well, to anyone's surprise, there are no plots in the folder. the loop >>finishes (i, fname and mname have values assigned) and executing >> >>png(fname,1000,1000) >>xyplot(N_female~eval(parse(text=i)) |group,xlab=i,ylab="Abundance") >>graphics.off() >> >>does produce a png in the folder. I assume this to be caused by thepng>>function, since removing the graphics.off() and playing with dev.off() >>and the likes did not help. anyone ideas?? am I missing the obvious?? >> >>______________________________________________ >>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.
Dear Sacha, On Mon, Mar 7, 2011 at 9:28 AM, Sacha Viquerat <tweedie-d at web.de> wrote:> hello list! I'm sorry, I just stumbled over this strange behaviour (at least > I am not able to explain the behaviour, therefore I assume it to be a > strange behaviour): > > attach(water) # I know, this is not recommendednot only not recommended, not needed. xyplot() has a data argument you could have used.> > names(water[3:10]) > [1] "temp" "pH" ? "DO" ? "BOD" ?"COD" ?"no3" ?"no2" ?"po4" > > for (i in names(water)[3:10]){ > ? ?fname<-paste("Henni/GFX/fem",i,".png",sep="") > ? ?mname<-paste("Henni/GFX/mal",i,".png",sep="") > ? ?png(fname,1000,1000) > ? ?xyplot(N_female~eval(parse(text=i)) |group,xlab=i,ylab="Abundance") > ? ?graphics.off() > ? ?png(mname,1000,1000) > ? ?xyplot(N_male~eval(parse(text=i)) |group,xlab=i,ylab="Abundance") > ? ?graphics.off() > } > > well, to anyone's surprise, there are no plots in the folder. the loop > finishes (i, fname and mname have values assigned) and executing > > png(fname,1000,1000) > xyplot(N_female~eval(parse(text=i)) |group,xlab=i,ylab="Abundance") > graphics.off() > > does produce a png in the folder. I assume this to be caused by the pngNo.> function, since removing the graphics.off() and playing with dev.off() andI always thought using dev.off() was the "normal" way, but it may just be *my* normal way.> the likes did not help. anyone ideas?? am I missing the obvious??It is obvious only insofar as it is noted in the FAQ. Here is a link: cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f short answer, wrap your call in print() like so: print(xyplot(yourargument)) HTH, Josh> > ______________________________________________ > 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. >-- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles joshuawiley.com
You need to print lattice objects. See the FAQ. -- David. On Mar 7, 2011, at 12:28 PM, Sacha Viquerat wrote:> hello list! I'm sorry, I just stumbled over this strange behaviour > (at least I am not able to explain the behaviour, therefore I assume > it to be a strange behaviour): > > attach(water) # I know, this is not recommended > > names(water[3:10]) > [1] "temp" "pH" "DO" "BOD" "COD" "no3" "no2" "po4" > > for (i in names(water)[3:10]){ > fname<-paste("Henni/GFX/fem",i,".png",sep="") > mname<-paste("Henni/GFX/mal",i,".png",sep="") > png(fname,1000,1000) > xyplot(N_female~eval(parse(text=i)) |group,xlab=i,ylab="Abundance") > graphics.off() > png(mname,1000,1000) > xyplot(N_male~eval(parse(text=i)) |group,xlab=i,ylab="Abundance") > graphics.off() > } > > well, to anyone's surprise, there are no plots in the folder. the > loop finishes (i, fname and mname have values assigned) and executing > > png(fname,1000,1000) > xyplot(N_female~eval(parse(text=i)) |group,xlab=i,ylab="Abundance") > graphics.off() > > does produce a png in the folder. I assume this to be caused by the > png function, since removing the graphics.off() and playing with > dev.off() and the likes did not help. anyone ideas?? am I missing > the obvious?? > > ______________________________________________ > 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.David Winsemius, MD West Hartford, CT