[R] How to open more windows to make more graphs at once!

José Rafael Ferrer Paris jr_frrr at yahoo.de
Wed Mar 7 16:06:41 CET 2007


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 at 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.



More information about the R-help mailing list