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
-----------------------------------------------------------------------
Paulo Barata
Fundacao Oswaldo Cruz (Oswaldo Cruz Foundation)
Rua Leopoldo Bulhoes 1480 - 8A
21041-210 Rio de Janeiro - RJ
Brazil
E-mail: pbarata at infolink.com.br
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
On Tue, 21 Nov 2006, 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.jpeg files do not have a dpi: they are dimensioned in pixels. I think you mean you want a file at 1200 ppi (pixels per inch), as 'dpi' (dots per inch) is a printer parameter (sometimes also used of monochrome screens).> 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?width=6*1200, height=4*1200, res=1200 Note that 1200ppi is a very high resolution, and 200dpi is more usual. Please take local advice on this issue, as I believe the problem is a misunderstanding of resolution. -- 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
Dear R-list members, I would like to draw a smooth arc. I can draw an arc parametrically, but this produces an arc too coarse, even allowing for different increments in sequence t in the example below. Function "symbols" (graphics) does produce a smooth circle, but it cannot produce an arc. Please see the following example, drawing complete circles: plot(-5:5,-5:5,type='n') ## draws circle with function symbols (package graphics) ## - inner circle is very smooth: symbols(0,0,circles=2,add=TRUE) ## draws circle parametrically - outer circle is too coarse: pi <- 4*atan(1) t <- seq(0,2*pi,0.02) lines(4*cos(t),4*sin(t)) Package "plotrix" has a function "draw.arc", but arcs produced with this function are also either too coarse or too polygonal, depending on the number of polygons used to approximate the arc. Is there a way to harness the characteristics of function "symbols" (graphics) to draw a smooth arc, not just a complete circle? I am using R 2.5.0, running under Windows XP. Thank you very much. Paulo Barata ----------------------------------------------------------------- Paulo Barata Fundacao Oswaldo Cruz (Oswaldo Cruz Foundation) Rua Leopoldo Bulhoes 1480 - 8A 21041-210 Rio de Janeiro - RJ Brazil E-mail: pbarata at infolink.com.br