[R] Change color in forest.rma (metafor)

Viechtbauer Wolfgang (STAT) wolfgang.viechtbauer at maastrichtuniversity.nl
Wed Aug 24 18:39:25 CEST 2011


Thank you, Bernd, for looking into this. 

Yes, at the moment, the color of the summary estimate for models without moderators is hard-coded (as black). I didn't think people may want to change that. I guess I was wrong =)

A dirty solution for the moment is to add:

addpoly(dfs, efac=6, row=-1, col="red", border="red", annotate=F, mlab="")

after the call to forest(). You will get a warning message (since the border argument gets passed to the text() function inside addpoly() and that's not a par for text), but you can just ignore that.

Best,

-- 
Wolfgang Viechtbauer 
Department of Psychiatry and Neuropsychology 
School for Mental Health and Neuroscience 
Maastricht University, P.O. Box 616 
6200 MD Maastricht, The Netherlands 
Tel: +31 (43) 368-5248 
Fax: +31 (43) 368-8689 
Web: http://www.wvbauer.com 


> -----Original Message-----
> From: Bernd Weiss [mailto:bernd.weiss at uni-koeln.de]
> Sent: Wednesday, August 24, 2011 16:22
> To: Paola Tellaroli
> Cc: wvb at metafor-project.org; r-help at r-project.org
> Subject: Re: [R] Change color in forest.rma (metafor)
> 
> Am 24.08.2011 07:50, schrieb Paola Tellaroli:
> > My script is the following:
> >
> > library(metafor)
> >
> > yi<-c(-0.1, 0.2, 0.3, 0.4)
> > sei<-c(0.4, 0.2, 0.6, 0.1)
> > vi<-sei^2
> > studi<-c("A", "B", "C", "D")
> > eventi.c<-c(10, 5, 7, 6)
> > n.c<-c(11, 34, 25, 20)
> > eventi.a<-c(2, 7, 6, 5)
> > n.a<-c(11, 35, 25, 15)
> > dfs<-rma(yi, vi, method="DL")
> > dfs
> >
> > windows(height=6, width=10, pointsize=10)
> > windowsFonts(B=windowsFont("Bookman Old Style"))
> >
> > forest.rma(dfs, slab=studi, xlim=c(-15, 10), ilab=cbind(eventi.c, n.c,
> > eventi.a, n.a), ilab.xpos=c(-9.5, -8, -6, -4.5), cex=1.2, at=c(-2, -1,
> 0, 1,
> > 2), family="B", xlab="Hazard Ratio (log scale)", mlab="Random Effects
> > Model", efac=5, col="red", border="red")
> > text(-10, -1.3, paste("Heterogeneity: I-squared=",
> paste(paste(round(dfs$I2,
> > 2), "%", sep=""), paste("p", round(dfs$QEp, 4), sep="="), sep=", "),
> > sep=""), font=4, cex=1.2, family="B")
> >
> > op<-par(cex=1.2, font=2, family="B", oma=c(0.5, 0.5, 0.5, 0.5),
> mar=c(0.5,
> > 0.5, 0.5, 0.5))
> > text(x=c(-9.5, -8, -6, -4.5), 6, c("Events", "N", "Events", "N"),
> cex=1.2 )
> > text(c(-8.7, -5.5, 8), 6.5, c("S", "A", "Log"))
> > text(-15, 6, "Trials", pos=4)
> > text(10, 6, "Hazard Ratio [95% CI]", pos=2)
> > par(op)
> >
> > Even if I have specified "col="red", border="red"", color of squares and
> > diamond rests black! Why?
> 
> As far as I know, "col" and "border" do only affect the fitted values
> ("diamonds"), i.e. the FEM/REM estimators (see ?forest.rma: "col:
> character string specifying the name of a color to use for _the fitted_
> values ('"darkgray"' by default).")
> 
> Furthermore, I had a quick look at the source code and it might be a
> bug. If I replace in line 2770 the line
> 
> cex * efac), col = "black", ...)
> 
> with
> 
> cex * efac), col = col, ...)
> 
> you can at least specify your own colour. Changing the border color
> seems a bit more tricky...
> 
> However, Wolfgang Viechbauer (the package author) is always a very
> responsive and helpful person and I suggest you better wait for his
> answer.
> 
> Bernd



More information about the R-help mailing list