Skip to content

quartz() and dpi

3 messages · Baptiste Auguie, Jo Frabetti

#
Hello all,

I am using quartz (on OS X obviously) to produce PDFs and PNGs from my
plots, for later inclusion in LaTeX.

I am typically using something like:

plot(0)
dev.print(quartz, file="foo.pdf", width=5, height=3)
dev.print(quartz, file="foo.png", width=5, height=3, dpi=72)

I want the sizes of the PDF and PNG to be *equal* in *inches*, which
works with dpi=72. However, when I increase the dpi parameter, instead
of producing an image of the same size with increased resolution, it
creates a larger image of resolution = 72. E.g. try

dev.print(quartz, file="foo-72.png", width=5, height=3, dpi=72)
dev.print(quartz, file="foo-300.png", width=5, height=3, dpi=300)
system("open -a Preview.app foo-*.png")

The inspector in Preview should show 72 dpi for both files. This is with:
R version 2.10.1 (2009-12-14)
x86_64-apple-darwin9.8.0

Is this a know bug/limitation? Is a solution planned? Is there a
workaround for now?

As a final note, I am aware that PDF is superior to PNG, particularly
in a LaTeX workflow; but for particularly complex plots, I sometimes
fall back on high resolution PNGs. Currently it forces me to add a
'scale' argument to includegraphics in latex for those. I would rather
leave the latex document alone, use extension-less file names
includegraphics and decide from R wether to produce a pdf or a png.

Thank you in advance,

JiHO
---
http://maururu.net
#
Hi,

I think it's a bug in quartz(). The following example uses png() with
cairo or quartz backends, and only cairo respects the size and
resolution (as verified in Adobe Photoshop).

 png(file="foo-300.png", type="quartz", units="in",width=5, height=3, res=300)
 plot(1,1)
 dev.off()

 png(file="foo-300.png", type="cairo", units="in",width=5, height=3, res=300)
 plot(1,1)
 dev.off()

As far as I can tell the Cairo device (CairoPNG) doesn't respect the
size either. It looks like your best option is to switch between pdf()
and png(type="cairo") using a wrapper like ggplot2::ggsave.

Best,

baptiste

sessionInfo()
R version 2.10.1 RC (2009-12-06 r50690)
i386-apple-darwin9.8.0

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] Cairo_1.4-5

loaded via a namespace (and not attached):
[1] tools_2.10.1
On 28 January 2010 02:23, JiHO <jo.lists at gmail.com> wrote:
#
Using a wrapper function is exactly what I am doing (because I need it
to save the occasional base R plot so ggsave won't work all the time).
However, after extensively testing the different devices, quartz is
the most desirable even for PNGs: png(type="cairo") messes up the
fonts. Helvetica is used by default and the X11 part of OS X (the
pango library specifically) cannot properly read the version of
Helvetica provided by the system (in many software, the normal variant
is actually bold). cairo uses pango so the fonts in the PNG don't look
as good as in quartz.

So basically I either have wrong size but correct fonts or wrong fonts
but correct size. I currently chose the fonts over the size since the
size can be corrected and the fonts cannot. BUt of course I would
rather not have to choose ;)

JiHO
---
http://maururu.net