Re: [R] How to open more windows to make more graphs at once!
Dear Monireh, try using lattice: library(lattice) set.seed(1234) dat <- data.frame(months=rep(1:10,80),upper = rnorm(800)+1, lower = rnorm(800)-1, observed = rnorm(800), best.sim = rnorm(800), stname = factor(gl(80, 10))) jpeg(filename = "Rplot%03d.jpeg") xyplot(best.sim+observed+lower+upper~months|stname,dat, layout=c(3,4),type="b",auto.key=T) dev.off() It should produce almost exactly what you want. Lattice is a very powerful tool for creating multiple graphics. You can customize the individual plots within the lattice using panel and prepanel functions, take a look at the documentation of the library and the documentation of xyplot and panel.xyplot. Lattice is a little bit more complex than "normal" plots in R, so you would have to spend more time in learning how to use its functionality, but it is worth trying. have a lot of fun JR El mié, 07-03-2007 a las 09:39 +0100, Faramarzi Monireh escribió: > 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. __ 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.
Re: [R] How to open more windows to make more graphs at once!
Alberto Monteiro wrote: > Ted Harding wrote: > >>>Creating more than one graphic windows is, as far as I know, not >>>possible in R. >> >> >>But, as to whether/to what extent X or equivalent is available for >>MS Windows, that is another question on which I have no expertise. >> > > X11() seems to work for Windows XP. Although I believe the preferred method is windows(). Best, Jim > > Alberto Monteiro > > __ > 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. -- James W. MacDonald, M.S. Biostatistician Affymetrix and cDNA Microarray Core University of Michigan Cancer Center 1500 E. Medical Center Drive 7410 CCGC Ann Arbor MI 48109 734-647-5623 ** Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues. __ 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.
Re: [R] How to open more windows to make more graphs at once!
Ted Harding wrote: > >> Creating more than one graphic windows is, as far as I know, not >> possible in R. > > But, as to whether/to what extent X or equivalent is available for > MS Windows, that is another question on which I have no expertise. > X11() seems to work for Windows XP. Alberto Monteiro __ 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.
Re: [R] How to open more windows to make more graphs at once!
On 07-Mar-07 ONKELINX, Thierry wrote: > Creating more than one graphic windows is, as far as I know, not > possible in R. It is if you are running R on Linux (in which the X Windowing System -- or X -- is the standard graphical system). As it says in "?X11": "This can only be done on machines that run X." Then each call to X11() opens a new graphics window, so you can have as many as you like. And, using the "display" parameter in X11(), if you have monitors for more than one machine on your desk you can "throw" each window to a monitor of your choice, giving you multiple graphics windows on multiple screens, all from the same run of R. But, as to whether/to what extent X or equivalent is available for MS Windows, that is another question on which I have no expertise. Ted. > But it's no problem to run a script which create > multiply > jpeg's. See ?jpeg on how to create jpeg's. > > Cheers, > > Thierry > > > > > ir. Thierry Onkelinx > > Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature > and Forest > > Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, > methodology and quality assurance > > Gaverstraat 4 > > 9500 Geraardsbergen > > Belgium > > tel. + 32 54/436 185 > > [EMAIL PROTECTED] > > www.inbo.be > > > > Do not put your faith in what statistics say until you have carefully > considered what they do not say. ~William W. Watt > > A statistical analysis, properly conducted, is a delicate dissection of > uncertainties, a surgery of suppositions. ~M.J.Moroney > >> -Oorspronkelijk bericht----- >> Van: [EMAIL PROTECTED] [mailto:r-help- >> [EMAIL PROTECTED] Namens Faramarzi Monireh >> Verzonden: woensdag 7 maart 2007 9:39 >> Aan: r-help@stat.math.ethz.ch >> Onderwerp: [R] How to open more windows to make more graphs at once! >> >> >> 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. > > __
Re: [R] How to open more windows to make more graphs at once!
On Wed, 2007-03-07 at 09:39 +0100, Faramarzi Monireh wrote: > 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 > Hi Monireh, I don't have your data set so I have generated some random data to illustrate one approach to this. ## generate some data set.seed(1234) dat <- data.frame(upper = rnorm(100), lower = rnorm(100), observed = rnorm(100), best_sim = rnorm(100), stname = factor(gl(5, 20), labels = letters[1:5])) ## because this is going to be called 45 times, I've wrapped it in a ## function, foo() ## Note the filename arg. It contains "%03d" which means that R will ## insert a number and produce many jpegs, varying by this number ## e.g. myplot1.jpeg, myplot2.jpeg - see ?jpeg. ## the "..." allow passing of arguments to jpeg foo <- function(x, filename = "Rplot%03d.jpeg", ...) { ## start the jpeg device jpeg(filename = filename, ...) ## store the parameter defaults and set a 2 by 2 plot regions opar <- par(mfrow = c(2,2)) ## this insures that the device is closed and defaults restored on ## function exit on.exit({dev.off(); par(opar)}) ## set up a loop to go over the levels of your factor for(i in levels(x$stname)) { ## do the plotting - here you need to add the plot commands ## you really want to use - these are just examples. plot(lower ~ upper, data = x, subset = stname == i) ## this just adds a lowess line, I use with() to make it easier ## to read. with(x, lines(lowess(upper[stname == i], lower[stname == i]), col = "red")) } invisible() } ## to use the function on the demo data ## uses default filename foo(dat) ## or passing arguments to jpeg() foo(dat, width = 600, height = 600, pointsize = 10) ## or using your own file name foo(dat, filename = "dataset1_%03d.jpeg", width = 600, height = 600, pointsize = 10) See ?jpeg to see why this works - the filename with "%03d" allows R to produce several jpegs. > > 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)) In the line below, where you set the x- and y-limits, it would be simpler and more readable to use range() instead of c(min(x), max(x) - so your plot call could be: plot.jpeg<- plot(xx,yy, type="n", xlim= range(xx), ylim=range(zz,yy,tt)*1.4), main= i, xlab="Month (1990-2002)", ylab="Discharge(m3/s)", font.axis=6) Also, you can format the y-label more nicely with: ylab = expression(paste("Discharge (", m^-3 * s^{-1}, ")")) HTH G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [t] +44 (0)20 7679 0522 ECRC [f] +44 (0)20 7679 0565 UCL Department of Geography Pearson Building [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street London, UK[w] http://www.ucl.ac.uk/~ucfagls/ WC1E 6BT [w] http://www.freshwaters.org.uk/ %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ 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.
Re: [R] How to open more windows to make more graphs at once!
Creating more than one graphic windows is, as far as I know, not possible in R. But it's no problem to run a script which create multiply jpeg's. See ?jpeg on how to create jpeg's. Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney > -Oorspronkelijk bericht- > Van: [EMAIL PROTECTED] [mailto:r-help- > [EMAIL PROTECTED] Namens Faramarzi Monireh > Verzonden: woensdag 7 maart 2007 9:39 > Aan: r-help@stat.math.ethz.ch > Onderwerp: [R] How to open more windows to make more graphs at once! > > > 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. __ 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.
Re: [R] How to open more windows to make more graphs at once!
Hello, See ?Devices ?dev.print e.g. X11() # opens a new screen device plot(1:10) # plots points on the device dev.print(jpeg, [args]) # prints from the X11 device to a jpeg file dev.off() # close X11 device or jpeg([args]) # opens a jpeg device (file) for plotting plot(1:10) # plots points on the device dev.off() # closes connection to the jpeg device Hope this helps. Regards, -- Nicolas Mazziotta The contents of this e-mail, including any attachments, are ...{{dropped}} __ 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.
[R] How to open more windows to make more graphs at once!
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.