[R] Cannot save histogram picture when run from script

Dieter Menne dieter.menne at menne-biomed.de
Fri Feb 1 09:32:01 CET 2008


Ng Stanley <stanleyngkl <at> gmail.com> writes:

> I am faced with a strange problem. My picture file is empty when the
> following statements were run from R script. But the picture file shows up
> correctly, when the commands are individually run from Rgui.
> 
> png(file="histogram_correlation.png", bg = "white")
> require(stats)
> histogram( ~ height | voice.part, data = singer, nint = 17,
>           endpoints = c(59.5, 76.5), layout = c(2,4), aspect = 1,
>           xlab = "Height (inches)")
> dev.off()
> 

The FAQ of FAQs, but admittely confusing (I remember Douglas Bates calling
Deepayan in the middle of the night in India): lattice graphics must be printed
in this context. I usually do it in two steps:

p = histogram(...)
print(p,(add layout if required here))

Dieter



More information about the R-help mailing list