6

So this is some generic data. I currently use the metafor package and par() function to make the plots side by side. However, I would like to ideally get rid of the study column in the second graph and the log RR estimates from both plots. I would like both forest plots to be moved closer together as well. Sorry for not providing data previously - I'm new at this.

library(metafor)
par(mfrow=c(1,2))

### load BCG vaccine data
data(dat.bcg)
### calculate log relative risks and corresponding sampling variances
dat <- escalc(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg)
### default forest plot of the observed log relative risks
forest(dat$yi, dat$vi)
### default forest plot of the observed log relative risks for second plot
forest(dat$yi, dat$vi)

===============================

Does anyone know how to make a side-by-side forest plot in r? I want to have the subgroup names on the left hand side, then two forest plots immediately to the right (beside each other) Somewhat like this http://www.nature.com/ng/journal/v43/n8/images_article/ng.882-F1.jpg but much simpler.

I have tried the par() function with metafor package but it does not work.

Cyrus Mohammadian
  • 4,982
  • 6
  • 33
  • 62
user3741672
  • 63
  • 1
  • 4
  • 2
    You really should show some sample data and the code you've tried (including what functions/packages you plan to use). Please read [how to make a great R reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). This will make it much easier for others to help you. – MrFlick Jun 15 '14 at 05:42
  • You could draw each individual forest plot using `ggplot` (**ggplot2**) and then use `grid.arrange` (**gridExtra**) to to bind tham together. – user20650 Jun 15 '14 at 13:00
  • Yes, need sample data for this. Google has plenty on this too. This might get you started. http://mcfromnz.wordpress.com/2012/11/06/forest-plots-in-r-ggplot-with-side-table/ – r.bot Jun 15 '14 at 13:49
  • I've looked at this for a while but none of the functions make this particularly easy. I've had to hack at the insides of the functions but it's still tricky to get everything to line up. – MrFlick Jun 16 '14 at 05:19
  • I dont necessarily need to use the metafor package...any package that can do the trick is fine by me.... Thanks for trying MrFlick – user3741672 Jun 16 '14 at 21:41

1 Answers1

9

This gets you pretty close:

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

par(mfrow=c(1,2))
par(mar=c(5,4,1,1))
forest(dat$yi, dat$vi, annotate=FALSE, cex=.8, at=seq(-3,2,1), digits=1, xlim=c(-6,2))
text(0, 15, "Figure 1", cex=.8, font=2)
par(mar=c(5,3,1,2))
forest(dat$yi, dat$vi, annotate=FALSE, slab=rep("",length(dat$yi)), cex=.8, at=seq(-3,2,1), digits=1, xlim=c(-5,3))
text(0, 15, "Figure 2", cex=.8, font=2)

side-by-side forest plots

Wolfgang
  • 2,810
  • 2
  • 15
  • 29