简体   繁体   中英

R: use cairo fallback resolution greater than 72dpi in cairo_pdf and cairo_ps

In grDevices R functions cairo_pdf and cairo_ps it is mentioned that when transparency (alpha channels) are used in vector output, it will rasterize the PDF or postscript exported graph at a resolution of 72 dpi : https://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/cairo.html

You can see the problem if you try

library(ggplot2)
cairo_ps(file = "test.eps",onefile = FALSE)
qplot(Sepal.Length, Petal.Length, data = iris, color = Species, size = Petal.Width, alpha = I(0.7))
dev.off()

as in the output (here zoomed in) the plot symbols are heavily pixelated then, showing it is indeed only using 72 dpi : 在此处输入图片说明

I was wondering how the fallback resolution could be increased to 600 dpi? In library(RGtk2) there is a command cairoSurfaceSetFallbackResolution , which I think is what is relevant here, but I would not know how to make grDevices use that parameter. Any thoughts?

Using postscript() btw also doesn't work, since that doesn't support transparency, and returns the error "semi-transparency is not supported on this device: reported only once per page".

The latest r-devel version has now added the extra argument fallback_resolution , to specify the resolution at which non-supported vector elements should be rasterized, and that seems to solve the problem. Eg :

library(ggplot2)
cairo_ps(file = "test.eps",onefile = FALSE,fallback_resolution=600)
qplot(Sepal.Length, Petal.Length, data = iris, color = Species, size = Petal.Width, alpha = I(0.7))
dev.off()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM