## 5.3 Saving the forest plots

Let us say I want to save the JAMA version of my forest plot now. To do this, I have to reuse the code with which I plotted my forest plot, and put it between pdf(file='name_of_the_pdf_i_want_to_create.pdf') and dev.off, both in separate lines. This saves the plot into a PDF in my working directory. This way, I can export the plot in different formats (you can find more details on the saving options here).

PDF

pdf(file = 'forestplot.pdf')
forest.jama <- forest(m.hksj.raw,
layout = "JAMA",
text.predict = "95% PI",
col.predict = "black",
colgap.forest.left = unit(15,"mm"))
dev.off() 

PNG

png(file = 'forestplot.png')
forest.jama <- forest(m.hksj.raw,
layout = "JAMA",
text.predict = "95% PI",
col.predict = "black",
colgap.forest.left = unit(15,"mm"))
dev.off() 

Scalable Vector Graphic

svg(file = 'forestplot.svg')
forest.jama <- forest(m.hksj.raw,
layout = "JAMA",
text.predict = "95% PI",
col.predict = "black",
colgap.forest.left = unit(15,"mm"))
dev.off()