if (FALSE) {
ggplot(mtcars, aes(mpg, wt)) + geom_point()
ggsave(file.path(tempdir(), "mtcars.pdf"))
ggsave(file.path(tempdir(), "mtcars.png"))
ggsave(file.path(tempdir(), "mtcars.pdf"), width = 4, height = 4)
ggsave(file.path(tempdir(), "mtcars.pdf"), width = 20, height = 20, units = "cm")
unlink(file.path(tempdir(), "mtcars.pdf"))
unlink(file.path(tempdir(), "mtcars.png"))
# specify device when saving to a file with unknown extension
# (for example a server supplied temporary file)
file <- tempfile()
ggsave(file, device = "pdf")
unlink(file)
}
Run the code above in your browser using DataLab