How to save a graph as a PDF to a PDF in Windows? (R; ggplot2)

How to save a graph as a PDF to a PDF in Windows? In R it is easy to save the graph as a pdf file, but how to save it as a4 file?

+4
source share
2 answers
pdf("a4_output.pdf", paper="a4") 

And if you want A4 format to be the default default, so you don't need to specify it:

 pdf.options(paper = "a4") 

The above work to build the default R, for ggplot you need to use the ggsave function. I'm not sure if ggplot has built-in paper sizes, but you can specify sizes in any units with ggsave , so for A4 you can do:

 ggsave(file="a4_output.pdf", width = 210, height = 297, units = "mm") 
+14
source

I came across this and found out that I need the correct device ( cairo_pdf ) to correctly print all the text. Works with grid.arrange too.

For a 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 using dplyr , you can use:

 ggplot(...) %>% ggsave( filename="yourfile.pdf", plot = ., device = cairo_pdf, width = 210, height = 297, units = "mm") 
+1
source

Source: https://habr.com/ru/post/1483063/


All Articles