How to save a graph as an a4 size pdf file under windows system? In R, it's easy to save a graph as a pdf file, but how to save it as an a4 size file?
pdf("a4_output.pdf", paper="a4")
And if you want A4 to be the default pdf size, so that you don't need to keep on specifying it:
pdf.options(paper = "a4")
The above works for default R plotting, for ggplot you need to use the ggsave
function. I'm not sure if ggplot has built-in paper sizes, but you can specify dimensions in any units with ggsave
, so for A4 you can do:
ggsave(file="a4_output.pdf", width = 210, height = 297, units = "mm")
I ran into this, and found out that I needed the correct device
(cairo_pdf
) to print all text correctly. Works with grid.arrange
too.
For portrait:
ggsave(filename="yourfile.pdf",
plot = yourplot,
device = cairo_pdf,
width = 210,
height = 297,
units = "mm")
For landscape:
ggsave(filename="yourfile.pdf",
plot = yourplot,
device = cairo_pdf,
width = 297,
height = 210,
units = "mm")
Or, with dplyr
you could use:
ggplot(...) %>%
ggsave(
filename="yourfile.pdf",
plot = .,
device = cairo_pdf,
width = 210,
height = 297,
units = "mm")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With