Skip to content

Instantly share code, notes, and snippets.

@sheymann
Created April 16, 2012 16:01
Show Gist options
  • Save sheymann/2399659 to your computer and use it in GitHub Desktop.
Save sheymann/2399659 to your computer and use it in GitHub Desktop.
R tip: Export a ggplot plot in PDF, EPS and PNG files
ExportPlot <- function(gplot, filename, width=2, height=1.5) {
# Export plot in PDF and EPS.
# Notice that A4: width=11.69, height=8.27
ggsave(paste(filename, '.pdf', sep=""), gplot, width = width, height = height)
postscript(file = paste(filename, '.eps', sep=""), width = width, height = height)
print(gplot)
dev.off()
png(file = paste(filename, '_.png', sep=""), width = width * 100, height = height * 100)
print(gplot)
dev.off()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment