[R] Printing to jpeg (dev.print)

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Oct 2 23:05:11 CEST 2007


On Tue, 2 Oct 2007, Marcin Kozak wrote:

> This may be an easy question, but let me ask it. When writing a plot
> to a jpeg file:

You do realize that is not what this does: it copies a plot from a screen 
device to a jpeg device?

>> plot(runif(30))
>> dev.print(file="test.jpeg", device=jpeg, width=600)
>
> the plot I receive has gray background, the result on no account I
> want to receive. The same situation occurs when printing to a bmp
> file. But when printing a pdf file, the background is white as it
> should be.

Why 'should' it be?  You haven't specified a white background anywhere, 
and on-screen the background is transparent not white on many devices 
including windows().

> What should I do to have a plot in a jpeg file with white
> background?

Specify a white background (bg="white") for the device you copy *from* or 
for the plot.  (The background is part of the plot.)

I presume you are on Windows, since you mention bmp, but please do tell us 
such things. If so, you are copying a plot with a transparent background, 
and that is why the jpeg is showing as grey (the canvas used). If you copy 
to png you get a transparent background and see whatever canvas your 
viewer uses.

Alternatively, plot on the jpeg() device directly rather than copying to 
it, for that device defaults to a white background.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list