Home > Back-end >  How to save a non-ggplot plot in R?
How to save a non-ggplot plot in R?

Time:05-11

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?

CodePudding user response:

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()
  • Related