[R] plot via xyplot not being saved
Hi everyone, it's been a while I've been trying to save a plot created via lattice:::xyplot if I have a file tst.R with the following code: y - rnorm(100) x - rnorm(100) z - sample(letters[1:4], 100, rep=T) library(lattice) bitmap(tst.png) xyplot(y~x|z) dev.off() and I source it, I get the tst.png file, which is a blank page. If I copy and paste instead, I get the correct plot. Any suggestion? Thank you very much, b sessionInfo() R version 2.5.0 (2007-04-23) x86_64-unknown-linux-gnu locale: LC_CTYPE=en_US.iso885915;LC_NUMERIC=C;LC_TIME=en_US.iso885915;LC_COLLATE =en_US.iso885915;LC_MONETARY=en_US.iso885915;LC_MESSAGES=en_US.iso885915 ;LC_PAPER=en_US.iso885915;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASU REMENT=en_US.iso885915;LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods [7] base other attached packages: lattice 0.15-4 __ 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] plot via xyplot not being saved
On 6/15/07, Benilton Carvalho [EMAIL PROTECTED] wrote: Hi everyone, it's been a while I've been trying to save a plot created via lattice:::xyplot if I have a file tst.R with the following code: y - rnorm(100) x - rnorm(100) z - sample(letters[1:4], 100, rep=T) library(lattice) bitmap(tst.png) xyplot(y~x|z) dev.off() and I source it, I get the tst.png file, which is a blank page. If I copy and paste instead, I get the correct plot. Any suggestion? Use source(..., echo = TRUE) -Deepayan __ 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] plot via xyplot not being saved
So, if those statements are inside a function, I have to make my function to have an 'echo' argument/functionality? eg.: ## begin test.R test - function(n){ y - rnorm(n) x - rnorm(n) z - sample(letters[1:4], n, rep=T) library(lattice) bitmap(tst.png) xyplot(y~x|z) dev.off() } test(100) ## end test.R source(test.R, echo=T) also fails in this case... thanks a lot, b On Jun 15, 2007, at 8:53 PM, [EMAIL PROTECTED] wrote: On 6/15/07, Benilton Carvalho [EMAIL PROTECTED] wrote: Hi everyone, it's been a while I've been trying to save a plot created via lattice:::xyplot if I have a file tst.R with the following code: y - rnorm(100) x - rnorm(100) z - sample(letters[1:4], 100, rep=T) library(lattice) bitmap(tst.png) xyplot(y~x|z) dev.off() and I source it, I get the tst.png file, which is a blank page. If I copy and paste instead, I get the correct plot. Any suggestion? Use source(..., echo = TRUE) -Deepayan __ 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] plot via xyplot not being saved
On 6/15/07, Benilton Carvalho [EMAIL PROTECTED] wrote: So, if those statements are inside a function, I have to make my function to have an 'echo' argument/functionality? eg.: ## begin test.R test - function(n){ y - rnorm(n) x - rnorm(n) z - sample(letters[1:4], n, rep=T) library(lattice) bitmap(tst.png) xyplot(y~x|z) dev.off() } test(100) ## end test.R source(test.R, echo=T) also fails in this case... Yes. The following will produce some output (the values of x + y and x - y) if you type it out at the R prompt: x - rnorm(10) y - rnorm(10) x + y x - y If you put that in a file and source it, nothing will get printed, unless you have echo=TRUE. If you define test - function(){ x - rnorm(10) y - rnorm(10) x + y x - y } calling test() at the R prompt will only print x - y and not x + y, and so on. This is all standard R behaviour. If you want something to be printed irrespective of context, use print(), e.g. print(x + y) or print(xyplot(y~x|z)) This is also mentioned in the R FAQ. -Deepayan __ 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] plot via xyplot not being saved
Thank you Deepayan, I understand the behavior of not printing out the results inside the functions. What I didn't know was that for xyplot() saving the plot actually meant save the result I see, which does not happen with plot(), in which case my function test() works just fine if I replaced xyplot() by plot(). Thank you very much, b On Jun 16, 2007, at 12:26 AM, [EMAIL PROTECTED] wrote: On 6/15/07, Benilton Carvalho [EMAIL PROTECTED] wrote: So, if those statements are inside a function, I have to make my function to have an 'echo' argument/functionality? eg.: ## begin test.R test - function(n){ y - rnorm(n) x - rnorm(n) z - sample(letters[1:4], n, rep=T) library(lattice) bitmap(tst.png) xyplot(y~x|z) dev.off() } test(100) ## end test.R source(test.R, echo=T) also fails in this case... Yes. The following will produce some output (the values of x + y and x - y) if you type it out at the R prompt: x - rnorm(10) y - rnorm(10) x + y x - y If you put that in a file and source it, nothing will get printed, unless you have echo=TRUE. If you define test - function(){ x - rnorm(10) y - rnorm(10) x + y x - y } calling test() at the R prompt will only print x - y and not x + y, and so on. This is all standard R behaviour. If you want something to be printed irrespective of context, use print(), e.g. print(x + y) or print(xyplot(y~x|z)) This is also mentioned in the R FAQ. -Deepayan __ 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.