6.2 Saving the forest plot

Let’s say I want to save the Forest Plot now. The easiest way to do this is to plot it to a graphics device instead of to the screen. Just like the function sink() redirected text output from the console tab to a text file, there are functions that redirect images from the plot tab to a file.

One of these functions is pdf(), which opens the PDF graphics device. You can then plot your image, it will be sent to the PDF, and then close the device again. This saves the plot into a PDF to the Working Directory.

This way, you can export the plot in different formats (you can find more details on the saving options here).



PDF

pdf(file='forestplot.pdf') # Open PDF device with specific file name
forest(m_re, slab = df$study_id) # Plot the forest
dev.off() # Turn the PDF device off

PNG

png(file='forestplot.png') # Open PNG device with specific file name
forest(m_re, slab = df$study_id) # Plot the forest
dev.off() 

Scalable Vector Graphic

svg(file='forestplot.svg') # Open SVG device with specific file name
forest(m_re, slab = df$study_id) # Plot the forest
dev.off()