[R] Question on big JPG plots in function warpping format

alexfang@stat.rutgers.edu alexfang at stat.rutgers.edu
Fri Feb 10 16:41:10 CET 2006



Hello:

I have problems generating big JPG plots in functions.  the following code runs
fine in the script:

#### runs fine in script, generate 40k "test1.jpg" in the given directory
plotPlatesAlong <- c(1:5)
plotDirPath <- paste(dataPath, "OutputPlots\\", sep="")
filename <-   paste(plotDirPath,"test1.jpg", sep="")
jpeg(file=filename)
plotHeatTrellis(dataPath, plotVariable = "Raw", plotPlatesAlong)
    # here plotHeatTrellis() generates a complicate plot, but it works
dev.off()
#### End of script


but if I wrap it in a function, it doesn't work.

######## put it in a function and run test(dataPath)
######## it will make "test1.jpg" in the given directory, but only 6k in size
######## and if I open the file, it's blank
test <- function(dataPath) {
plotPlatesAlong <- c(1:5)
plotDirPath <- paste(dataPath, "OutputPlots\\", sep="")
filename <-   paste(plotDirPath,"test1.jpg", sep="")
jpeg(file=filename) #
plotHeatTrellis(dataPath, plotVariable = "Raw", plotPlatesAlong)
dev.off()
}
######### enf of the program


I've tested the simple plot function, like 

########## works fine both with in script and function wrapping format
testplot <- function(plotDirPath) {
filename1 <- paste(plotDirPath, "test1.jpg",sep="")
jpeg(file=filename1)
plot(1:10, rnorm(10, 0), type="b")
dev.off()
}
###########

Any one have any clues, why this happen and how could I fix my code and my mine
working also in the function wrapping format?  Thanks.


best, Alex




More information about the R-help mailing list