Created
March 19, 2012 05:22
-
-
Save wch/2096726 to your computer and use it in GitHub Desktop.
PNG output tests in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
p <- ggplot(mtcars, aes(cyl, mpg)) + geom_point() | |
# Standard png device, with type="cairo" | |
# Result: not antialiased | |
png('png_cairo.png', type="cairo") | |
p | |
dev.off() | |
# Standard png device, with type="cairo-png" | |
# Result: not antialiased | |
# Setting antialias argument to "subpixel" does nothing | |
png('png_cairo-png.png', type="cairo-png", antialias="subpixel") | |
p | |
dev.off() | |
# Using png with quartz | |
# Result: antialiased | |
# Problems: works only on Mac | |
png('png_quartz.png', type="quartz") | |
p | |
dev.off() | |
# Using cairoPNG from Cairo library. | |
# Result: antialiased | |
# Problems: fonts are messed up | |
library(Cairo) | |
CairoPNG('CairoPNG.png') | |
p | |
dev.off() | |
# ggsave with Cairo_png from cairoDevice | |
# Result: antialiased output | |
# Issues: | |
# - requires Cairo library (~56MB download on Mac) | |
# - needs to be tested on Windows, Linux | |
# Problems: Fonts are inconsistent across platforms | |
library(cairoDevice) | |
p | |
ggsave('Cairo_png.png', device=Cairo_png, width=5, height=5, dpi=72) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great script. I noted exactly the same problems.