Skip to content

Instantly share code, notes, and snippets.

@wch
Created March 19, 2012 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wch/2096726 to your computer and use it in GitHub Desktop.
Save wch/2096726 to your computer and use it in GitHub Desktop.
PNG output tests in R
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)
@valentas-kurauskas
Copy link

Great script. I noted exactly the same problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment