The metafor Package

A Meta-Analysis Package for R

User Tools

Site Tools


Table of Contents

Forest Plot


A forest plot is a commonly used visualization technique in meta-analyses, showing the results of the individual studies (i.e., the estimated effects or observed outcomes) together with their (usually 95%) confidence intervals. A four-sided polygon, sometimes called a summary 'diamond', is added to the bottom of the plot, showing the summary estimate based on the model (with the center of the polygon corresponding to the estimate and the left/right edges indicating the confidence interval limits). Below is an example of such a forest plot.



### copy BCG vaccine meta-analysis data into 'dat'
dat <-
### calculate log risk ratios and corresponding sampling variances (and use
### the 'slab' argument to store study labels as part of the data frame)
dat <- escalc(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat,
              slab=paste(author, year, sep=", "))
### fit random-effects model
res <- rma(yi, vi, data=dat)
### forest plot with extra annotations
forest(res, atransf=exp, at=log(c(0.05, 0.25, 1, 4)), xlim=c(-16,6),
       ilab=cbind(tpos, tneg, cpos, cneg), ilab.lab=c("TB+","TB-","TB+","TB-"),
       ilab.xpos=c(-9.5,-8,-6,-4.5), cex=0.75, header="Author(s) and Year",
       mlab="", shade=TRUE)
text(c(-8.75,-5.25), res$k+3, c("Vaccinated", "Control"), cex=0.75, font=2)
### add text with Q-value, dfs, p-value, and I^2 statistic
text(-16, -1, pos=4, cex=0.75, bquote(paste(
     "RE Model (Q = ", .(fmtx(res$QE, digits=2)),
     ", df = ", .(res$k - res$p), ", ",
     .(fmtp(res$QEp, digits=3, pname="p", add0=TRUE, sep=TRUE, equal=TRUE)), "; ",
     I^2, " = ", .(fmtx(res$I2, digits=1)), "%)")))
plots/forest_plot.txt ยท Last modified: 2024/06/07 12:35 by Wolfgang Viechtbauer