[R-meta] forest plot using metafor: how to add CIs as line segments

Viechtbauer Wolfgang (SP) wolfgang.viechtbauer at maastrichtuniversity.nl
Thu Aug 17 10:41:58 CEST 2017

I don't see an easy way of doing this directly with forest()/addpoly().

You can do this though with a cheap trick. Just draw over those values with a white rectangle. With a bit of trial and error, I found that this would work:

rect(6,-3.2,8.8,-0.8, col="white", border=NA)

Not very elegant, but gets the job done.

Note that if you change the dimensions of the plotting device, you will have to adjust the coordinates (leave out 'border=NA' to see where the rectangle is being drawn).


-----Original Message-----
From: Sophia Kyriakou [mailto:sophia.kyriakou17 at gmail.com] 
Sent: Thursday, August 17, 2017 00:36
To: Viechtbauer Wolfgang (SP)
Cc: r-sig-meta-analysis at r-project.org
Subject: Re: [R-meta] forest plot using metafor: how to add CIs as line segments

Hi Wolfgang,
Thanks for this, this is exactly what I asked for. Because I want to report confidence intervals computed using approaches that do not estimate the model parameters. 
For this reason I would also like to delete the -2.80 values on the last three rows of the right column so that only the confidence intervals are reported and the estim$pred are not.
Does forest() allow that?

On Wed, Aug 16, 2017 at 11:26 PM, Viechtbauer Wolfgang (SP) <wolfgang.viechtbauer at maastrichtuniversity.nl> wrote:
Hi Sophia,

I am not 100% sure if I understand what you want, but try:

forest(..., efac=c(1,0))


addpoly(..., efac=0)

and see if this is what you want.

By the way, you do not have to use forest.rma() -- using forest() is sufficient.


Wolfgang Viechtbauer, Ph.D., Statistician | Department of Psychiatry and
Neuropsychology | Maastricht University | P.O. Box 616 (VIJV1) | 6200 MD
Maastricht, The Netherlands | +31 (43) 388-4170 | http://www.wvbauer.com

-----Original Message-----
From: R-sig-meta-analysis [mailto:r-sig-meta-analysis-bounces at r-project.org] On Behalf Of Sophia Kyriakou
Sent: Wednesday, August 16, 2017 22:51
To: r-sig-meta-analysis at r-project.org
Subject: [R-meta] forest plot using metafor: how to add CIs as line segments


At the moment I have a forest plot obtained using the following code chunk.

data <- data.frame(y = c(-1.90, 1.00, -3.50, -5.90, -4.00),
sigma2 = c(0.34, 0.84, 1.37, 1.37, 0.28),
author = c("Study 1","Study 2","Study 3","Study 4","Study 5"))
estim <- data.frame(pred = c(-2.80,-2.80),LRlow = c(-4.78,-5.26),LRup =

res <- rma(y, sigma2, data=data, method = "ML")
forest.rma(res, xlim=c(-23, 15), at=seq(-10,4,2), slab=data$author,
ylim=c(-3, 8), xlab="Change in DBP", mlab="")
text(par("usr")[2], 7, pos=2, "DBP Change, [95% CI]", font=2)
text(par("usr")[1], -1, pos=4, "ML")
addpoly(estim$pred, ci.lb=estim$LRlow, ci.ub=estim$LRup, rows=-2,
mlab=c("DL", "DR"))

I would like to change the diamonds that  represent confidence intervals
into horizontal line segments, indicating the lower and upper limits of the
confidence interval. I am not interested in showing the estimated overall
effect of the model.
Is that possible?

Thanks in advance.

More information about the R-sig-meta-analysis mailing list