[R] saving graphics in jpeg format
Marc Schwartz
marc_schwartz at comcast.net
Wed Nov 22 01:46:28 CET 2006
On Tue, 2006-11-21 at 22:29 -0200, Paulo Barata wrote:
> Dear R users,
>
> I need to save a graph in jpeg format. After plotting the graph,
> when the graphics window is active, in the File menu, the
> Save as / Jpeg / 100% quality correctly saves the graph in jpeg format.
> But I would like to know, how could I control the resolution (in dpi)
> of the saved jpeg file? I need to produce a jpeg at 1200 dpi.
>
> I have tried also the jpeg function in the package grDevices.
> A simple command like this works correctly:
>
> jpeg(filename="test01.jpg", width = 800, height = 600, quality = 100,
> pointsize = 250)
> barplot(1:5,col=1:5)
> dev.off()
>
> But I can't figure out the relation between pointsize, pixels, points
> and dpi. For example, to be specific, to save a graph measuring
> width = 6 inches, height = 4 inches, at 1200 dpi, which parameters
> should I use in the jpeg function?
>
> I have consulted the R documentation and the R list archive, but
> haven't found any proper (to me) information on this matter.
>
> I am using R 2.4.0 running under Windows XP.
>
> Thank you very much.
>
> Regards,
>
> Paulo Barata
>
See ?bitmap, for which you will need Ghostscript installed:
bitmap("test.jpg", res = 1200, height = 4, width = 6, type = "jpeg")
barplot(1:5,col=1:5)
dev.off()
As an FYI, the file ends up being 672 Kb.
HTH,
Marc Schwartz
More information about the R-help
mailing list