To export multiple plots to PDF in R, you can use pdf() function and function. The pdf() function opens a graphics device to save plots to a PDF file, while closes the graphics device and saves the file.

The following method shows how you can do it with syntax.

Method 1: Use pdf() and Function


for (i in data) {   
  plot(x, y)   

The following example shows how to export multiple plots to pdf in R using pdf() and function.

Using pdf() and Function

Let’s see how we can use pdf() and function to export multiple plots to pdf in r:

# Create dataframe
df <- data.frame(Machine_name=c("A","B","C","D","E","F","G","H"),
                 Pressure1=c(78.2, 28, 71.7, 80.21, 72.7, 30, 84.21, 76.2),
                 Temperature1=c(31, 33, 36, 37, 36, 33, 37, 31),

# Specify path to save PDF 
destination = 'R_plots1.pdf'

# Open PDF file

# Save plots to PDF
for (i in df$Pressure1) {   
  plot(x, y)   

# Turn off PDF plotting file 

Here the above code shows how to export plots to pdf file using pdf() and function.