How to save a non-ggplot plot in R?

780 Views Asked by At

I have a forest plot from the package metafor. As it's not a ggplot, I cannot use my favourite ggsave(). I have tried functions like png(filename="forest_plot_bmj.png", res=315, width=3312, height=1228) but the outcome I get is different than what I see in the console output. What would be your suggestion?

1

There are 1 best solutions below

0
On BEST ANSWER

In base R plots, one needs to define the start of the plotting action e.g. with png and the end of the plotting with dev.off():

library(metafor)

dat <- escalc(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg)

png("out.png")
forest(dat$yi, dat$vi)
dev.off()