[R] quartz() and dpi

baptiste auguie baptiste.auguie at googlemail.com
Thu Jan 28 10:32:28 CET 2010


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:
> 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:
>
>> sessionInfo()
> 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
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list