Hi, I have the following script: ---- t.R --- grafica <- function() { v <- read.csv('preprocessed/komolongma.ece.uprm.edu.active',sep=',') x <- as.ts(v$active) bitmap(file="output.png") densityplot(~x,col='blue',main='Density Plot') dev.off() } grafica() ---- t.R --- When I "sourced" it from R prompt, it quietly runs. However the "output.png" generated contains any visible data. I said that, because the file is created and it has 2062 bytes. --- execution --- > library(lattice) > source(file="t.R") > --- execution --- Now, if I sequentially run the lines above in the R prompt, the "output.png" file contains a graphical representation of the data. --- execution 2 ---- > v <- read.csv('preprocessed/komolongma.ece.uprm.edu.active',sep=',') > x <- as.ts(v$active) > bitmap(file="output.png") > densityplot(~x,col='blue',main='Density Plot') > dev.off() ---- execution 2 --- What is wrong with the densityplot function that produces any output when is invoked from a script? Someone has a script invoking the densityplot function? Thanks a lot for your help.
Bill.Venables at csiro.au
2008-Aug-26 23:20 UTC
[R] awkward behavior with densityplot function
Lattice functions do not create plots. In this respect they are quite different to functions like plot(...), hist(...) &c, which do create plots. If you want to see the plot from a lattice function, you need to print the object it creates. It's the action of printing that creates the graphical image. This happens automatically at the command line, but if you want it to happen inside the function you need to use print(...) explicitly. So your function should be as in the following: ---- t.R --- grafica <- function() { v <- read.csv('preprocessed/komolongma.ece.uprm.edu.active',sep=',') x <- as.ts(v$active) bitmap(file="output.png") print(densityplot(~x,col='blue',main='Density Plot')) ###<<<--- dev.off() invisible(v) ### further suggestion. } grafica() ---- t.R --- Bill Venables http://www.cmis.csiro.au/bill.venables/ -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of John Sanabria Sent: Wednesday, 27 August 2008 9:08 AM To: r-help at r-project.org Subject: [R] awkward behavior with densityplot function Hi, I have the following script: ---- t.R --- grafica <- function() { v <- read.csv('preprocessed/komolongma.ece.uprm.edu.active',sep=',') x <- as.ts(v$active) bitmap(file="output.png") densityplot(~x,col='blue',main='Density Plot') dev.off() } grafica() ---- t.R --- When I "sourced" it from R prompt, it quietly runs. However the "output.png" generated contains any visible data. I said that, because the file is created and it has 2062 bytes. --- execution --- > library(lattice) > source(file="t.R") > --- execution --- Now, if I sequentially run the lines above in the R prompt, the "output.png" file contains a graphical representation of the data. --- execution 2 ---- > v <- read.csv('preprocessed/komolongma.ece.uprm.edu.active',sep=',') > x <- as.ts(v$active) > bitmap(file="output.png") > densityplot(~x,col='blue',main='Density Plot') > dev.off() ---- execution 2 --- What is wrong with the densityplot function that produces any output when is invoked from a script? Someone has a script invoking the densityplot function? Thanks a lot for your help. ______________________________________________ R-help at r-project.org 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.
See FAQ 7.22 On 27/08/2008, at 11:07 AM, John Sanabria wrote:> Hi, > > I have the following script: > ---- t.R --- > grafica <- function() { > v <- read.csv('preprocessed/komolongma.ece.uprm.edu.active',sep=',') > x <- as.ts(v$active) > bitmap(file="output.png") > densityplot(~x,col='blue',main='Density Plot') > dev.off() > } > grafica() > ---- t.R --- > > When I "sourced" it from R prompt, it quietly runs. However the > "output.png" generated contains any visible data. I said that, > because the file is created and it has 2062 bytes. > --- execution --- > > library(lattice) > > source(file="t.R") > > > --- execution --- > > Now, if I sequentially run the lines above in the R prompt, the > "output.png" file contains a graphical representation of the data. > --- execution 2 ---- > > v <- read.csv('preprocessed/komolongma.ece.uprm.edu.active',sep=',') > > x <- as.ts(v$active) > > bitmap(file="output.png") > > densityplot(~x,col='blue',main='Density Plot') > > dev.off() > ---- execution 2 --- > > What is wrong with the densityplot function that produces any > output when is invoked from a script? > Someone has a script invoking the densityplot function?###################################################################### Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
Apparently Analagous Threads
- no output when run densityplot...
- Problems drawing a colored 'rug' in the Lattice 'densityplot'
- How to generate a figure using par( ) with some densityplot( )'s
- small issue with densityplot
- How to adjust y-axis when using panel.densityplot within histogram function