Hello,
I would like to create a sequence of plots (using a for loop). I read in the FAQ that print() has to be used in order to obtain any output. This works perfectly fine as long as I only consider one function call in the loop, but I would like to add mtext() to the each plot in the loop. Unfortunately, this did not work. Any suggestions? As you can see from the provided example, there is another problem with such animations: You do not see any difference in the plots (because only the "height" changes). Is there any possibility to keep a fixed scale for the colorkey (fixed labels and also fixed colors) and to see the different heights of the function from the colors (e.g. the first plot should be mainly gray (as it is the "lowest"), the last one mainly white (as it is the "highest")). Thanks very much! marius Here is a complete minimal example: remove(list=objects()) library(lattice) for(i in 1:4){ output_file_path<-paste("~/Desktop/test_",i,".png",sep="") x<-rep(seq(-3,3,length=50),50) y<-rep(seq(-3,3,length=50),each=50) z<-x*y+10*i trellis.device(png,color=F,file=output_file_path) print(wireframe (z~x*y,drape=T,distance=0,zoom=0.84,cuts=100,col.regions=gray (100:400/400),colorkey=list(tick.number=6))) #print(mtext(paste("Parameter= ",1,sep=""),side=3,line=0)) #This does not work! dev.off() } ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html |
mtext() is not a lattice function. Could you not use the 'main'
argument? Peter Ehlers Marius Hofert wrote: > Hello, > > I would like to create a sequence of plots (using a for loop). I read > in the FAQ that print() has to be used in order to obtain any output. > This works perfectly fine as long as I only consider one function > call in the loop, but I would like to add mtext() to the each plot in > the loop. Unfortunately, this did not work. Any suggestions? > > As you can see from the provided example, there is another problem > with such animations: You do not see any difference in the plots > (because only the "height" changes). Is there any possibility to keep > a fixed scale for the colorkey (fixed labels and also fixed colors) > and to see the different heights of the function from the colors > (e.g. the first plot should be mainly gray (as it is the "lowest"), > the last one mainly white (as it is the "highest")). > > Thanks very much! > > marius > > Here is a complete minimal example: > > remove(list=objects()) > library(lattice) > for(i in 1:4){ > output_file_path<-paste("~/Desktop/test_",i,".png",sep="") > x<-rep(seq(-3,3,length=50),50) > y<-rep(seq(-3,3,length=50),each=50) > z<-x*y+10*i > trellis.device(png,color=F,file=output_file_path) > print(wireframe > (z~x*y,drape=T,distance=0,zoom=0.84,cuts=100,col.regions=gray > (100:400/400),colorkey=list(tick.number=6))) > #print(mtext(paste("Parameter= ",1,sep=""),side=3,line=0)) #This > does not work! > dev.off() > } > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html |
In reply to this post by mhofert
Marius Hofert wrote: > Hello, > > I would like to create a sequence of plots (using a for loop). I read > in the FAQ that print() has to be used in order to obtain any output. > This works perfectly fine as long as I only consider one function > call in the loop, but I would like to add mtext() to the each plot in > the loop. Unfortunately, this did not work. Any suggestions? > > As you can see from the provided example, there is another problem > with such animations: You do not see any difference in the plots > (because only the "height" changes). Is there any possibility to keep > a fixed scale for the colorkey (fixed labels and also fixed colors) > and to see the different heights of the function from the colors > (e.g. the first plot should be mainly gray (as it is the "lowest"), > the last one mainly white (as it is the "highest")). > > Thanks very much! > > marius > > Here is a complete minimal example: > > remove(list=objects()) > library(lattice) > for(i in 1:4){ > output_file_path<-paste("~/Desktop/test_",i,".png",sep="") > x<-rep(seq(-3,3,length=50),50) > y<-rep(seq(-3,3,length=50),each=50) > z<-x*y+10*i > trellis.device(png,color=F,file=output_file_path) > print(wireframe > (z~x*y,drape=T,distance=0,zoom=0.84,cuts=100,col.regions=gray > (100:400/400),colorkey=list(tick.number=6))) > #print(mtext(paste("Parameter= ",1,sep=""),side=3,line=0)) #This > does not work! > dev.off() > } > I think the "page" argument will help you the title (or simply use "main"; see ?xyplot). For the colorkey, set the "zlim" and "at" arguments. library(lattice) for(i in 1:4) { output_file_path <- paste("./test_", i, ".png", sep = "") x <- rep(seq(-3, 3, length = 50), 50) y <- rep(seq(-3, 3, length = 50), each = 50) z <- x * y + 10 * i trellis.device(png, color = FALSE, file = output_file_path) w <- wireframe(z ~ x * y, drape = TRUE, distance = 0, zoom = 0.84, cuts = 100, col.regions = gray(100:400/400), page = function(n) { label <- paste("Parameter = ", i, sep = "") ltext(0.5, 1, label) }, zlim = c(0, 50), at = seq(0, 50, length = 10), colorkey = list(tick.number = 6)) print(w) dev.off() } HTH, --sundar ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html |
In reply to this post by mhofert
On 5/29/06, Marius Hofert <[hidden email]> wrote:
> Hello, > > I would like to create a sequence of plots (using a for loop). I read > in the FAQ that print() has to be used in order to obtain any output. > This works perfectly fine as long as I only consider one function > call in the loop, but I would like to add mtext() to the each plot in > the loop. Unfortunately, this did not work. Any suggestions? Others have already responded to this. > As you can see from the provided example, there is another problem > with such animations: You do not see any difference in the plots > (because only the "height" changes). Is there any possibility to keep > a fixed scale for the colorkey (fixed labels and also fixed colors) > and to see the different heights of the function from the colors > (e.g. the first plot should be mainly gray (as it is the "lowest"), > the last one mainly white (as it is the "highest")). It seems to me that you are missing the primary point of Trellis graphics, which is not having to manually manage such details in a multipanel plot. Consider the following (which should produce 4 files with a png device): library(lattice) x<-rep(seq(-3,3,length=50),50) y<-rep(seq(-3,3,length=50),each=50) z1 <- x * y + 10 * 1 z2 <- x * y + 10 * 2 z3 <- x * y + 10 * 3 z4 <- x * y + 10 * 4 wireframe(z1 + z2 + z3 + z4 ~ x * y, outer = TRUE, drape = TRUE, zlab = "z", layout = c(1, 1), distance=0,zoom=0.84, cuts=100, col.regions=gray(100:400/400), colorkey=list(tick.number=6)) Caveat: this won't work if you want the z-axis completely filled up in each panel. -Deepayan ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html |
Free forum by Nabble | Edit this page |