Dear R users, I have a data frame (test) including five columns of upper (numeric), lower (numeric), observed (numeric), best_sim (numeric) and stname (factor with 80 levels, each level with different length). Now I would like to write a short program to draw one graph as follow for each level of stname but I would like also to draw each time 12 graphs for the 12 levels of stname in the same graphic windows and save it as "jpeg' file . This means at the end I will have 7 (80 levels/12=7) graphic windows and 7 jpeg files each one with 12 graphs (the last one with 8 graphs) for the 12 levels of stname. I already wrote the following script to do it each time for 12 levels of stname but I have to change script each time for the another 12 levels [line 3 in the script for example: for( i in levels(test$stname)[12:24))] and I do not know how can I save the obtained graphs (seven graphic windows) as jpeg files (e.g. plot1.jpeg, plot2.jpeg and so on). As I have 45 dataset like this it would be gr! eat if somebody can help me to complete this script to do all together for a dataset using a script. Thank you very much in advance for your cooperation, Monireh
windows(9,9) par(mfrow = c(3,4)) for( i in levels(test$stname)[1:12]) { data<- test[test$stname==i,] xx <- c(1:length(data$upper), length(data$upper):1) yy <- c(data$upper, rev(data$lower)) zz<- data$observed tt<- data$Best_Sim par(lab =c(10,15,2)) plot.jpeg<- plot(xx,yy, type="n", xlim=c(min(xx), max(xx)), ylim=c(min(zz,yy,tt), max(yy,zz,tt)*1.4), main= i, xlab="Month (1990-2002)", ylab="Discharge(m3/s)", font.axis=6) polygon(xx, yy, col="green", border = "NA") lines(zz, col="blue", lwd=1.5) lines(tt,col="red", lwd=1.5) legend(length(zz)-60, max(yy,zz,tt)*1.45, c("Upper Limit", "Lower Limit", " Observed","Best etimation") , lwd=c(10, 1,1.7,1.7), bty="n", col= c("green", "white", "blue","red")) } ______________________________________________ R-help@stat.math.ethz.ch 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.