[R] package metafor: error when setting 'col' and 'at' for a forest plot

Viechtbauer Wolfgang (STAT) wolfgang.viechtbauer at maastrichtuniversity.nl
Mon Jan 7 11:15:50 CET 2013


Dear Brian,

At the moment, the various forest() functions are not meant to accept 'col' as an argument. While it is indeed possible to specify a 'col' argument, it will be passed on via the ... argument to further functions within forest() and this is where things can go awry. 

To give a more technical explanation, let's look at your example. First, note that the highest 'at' value you specified is log(10), which is approximately 2.30. However, the highest upper CI bound in your dataset is 2.9. Therefore, the forest() function wants to draw a right-pointed arrow for that study using the polygon() function. The code within forest() looks something like this:

polygon(<lots of other stuff>, col="black", ...)

When you specify a 'col' argument, it is passed on to polygon() via ... -- but col="black" is already hard-coded in forest() and so you get the "formal argument "col" matched by multiple actual arguments" error.

The issue of changing colors in the forest() functions has come up before:

https://stat.ethz.ch/pipermail/r-help/2011-August/287788.html

In fact, the problems associated with allowing the user to specify colors in high-level plotting functions, such as forest(), was nicely discussed in a recent article by Paul Murrell in the R Journal:

http://journal.r-project.org/archive/2012-2/RJournal_2012-2_Murrell.pdf

I may add functionality to the forest() functions to handle a 'col' argument for specifying row colors, but I will have to evaulate carefully how well that will work. Also, I would then need to change the current 'col' argument in the forest.rma() function -- breaking backwards compatability :/

Back to your example. You can actually get it to work if you use:

forest(forest$OR, ci.lb=forest$Low, ci.ub=forest$High,  at=log(c(.05, .25, 1, 20)), slab=forest$SNP, atransf=exp)

in which case the values of 'at' encompass the CI bounds of all studies. Then the forest() function does not use polygon(), but segments() and here 'col' is not hard-coded. One (probably) unintended consequence of using 'col' this way is that the x axis label is also given a different color. 

A few other notes:

1) Calling your data frame 'forest' is probably not a good idea -- since that is the name of a function.

2) Your data appear to be (raw -- not log transformed) odds ratios and the corresponding CI bounds. So, you should not be using the atransf arguments -- or you would be transforming your odds ratios to exp(ORs). Probably closer to what you want is:

dat <- read.table(header=TRUE, text="
SNP   Group   High   Low   OR
rs1137101   A   1.21   0.87   1.03
rs1137101   B   2.11   1.21   1.6
rs1137101   C   2.9   1.42   2.03
rs1042522   A   1.12   0.84   0.97
rs1042522   B   1.15   0.79   0.95
rs1042522   C   0.92   0.5   0.7
rs1625895   A   1.14   0.76   0.93
rs1625895   B   1.15   0.75   0.93
rs1625895   C   NA   NA   NA
ACEI/D   A   1.55   0.79   1.11
ACEI/D   B   1.25   0.76   0.98
ACEI/D   C   0.85   0.41   0.59
")

forest(dat$OR, ci.lb=dat$Low, ci.ub=dat$High, col=c(1,2,3), at=c(.25, 1, 2, 3), slab=dat$SNP, refline=1, xlab=" ", xlim=c(-1.5,5.5))
mtext("Odds Ratio", side=1, line=2.5, adj=0.45)

where I manually add the x axis label, so that it is in black. Again, though, using 'col' this way is technically not intended (even though it does work here).

I hope this helps!

Best,
Wolfgang

--   
Wolfgang Viechtbauer, Ph.D., Statistician   
Department of Psychiatry and Psychology   
School for Mental Health and Neuroscience   
Faculty of Health, Medicine, and Life Sciences   
Maastricht University, P.O. Box 616 (VIJV1)   
6200 MD Maastricht, The Netherlands   
+31 (43) 388-4170 | http://www.wvbauer.com   

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of Brian Z Ring
> Sent: Sunday, January 06, 2013 05:48
> To: 'David Winsemius'; r-help at r-project.org
> Subject: Re: [R] package metafor: error when setting 'col' and 'at' for a
> forest plot
> 
> Good suggestion, and yes, the given examples work. Using a modification of
> one of the supplied examples, where in the final line I only added the
> parameter col=c(1,2,3):
> 
> data(dat.bcg)
> dat <- escalc(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg,
> data=dat.bcg, append=TRUE)
> forest(dat$yi, dat$vi, slab=paste(dat$author, dat$year, sep=", "),
> atransf=exp, at=log(c(.05,.25,1,4,20)), col=c(1,2,3))
> 
> I get a plot similar to what I want to achieve. My code:
> 
> forest(forest$OR, ci.lb=forest$Low, ci.ub=forest$High,  col=c(1,2,3),
> at=log(c(.05, .25, 1, 10)), slab=forest$SNP, atransf=exp)
> 
> differs in the data and using confidence intervals instead of vi (sample
> variance). The parameters being changed in my line of code are fairly
> simple, just color of each row and the x axis tick marks. Setting each of
> these independently with my data works fine, it's only when I try to do
> both
> that it fails. I'm still stuck.
> 
> Here is some example data that should reproduce the error:
> SNP	Group	High	Low	OR
> rs1137101	A	1.21	0.87	1.03
> rs1137101	B	2.11	1.21	1.6
> rs1137101	C	2.9	1.42	2.03
> rs1042522	A	1.12	0.84	0.97
> rs1042522	B	1.15	0.79	0.95
> rs1042522	C	0.92	0.5	0.7
> rs1625895	A	1.14	0.76	0.93
> rs1625895	B	1.15	0.75	0.93
> rs1625895	C	NA	NA	NA
> ACEI/D	A	1.55	0.79	1.11
> ACEI/D	B	1.25	0.76	0.98
> ACEI/D	C	0.85	0.41	0.59
> 
> -----Original Message-----
> From: David Winsemius [mailto:dwinsemius at comcast.net]
> Sent: Sunday, January 06, 2013 2:31 AM
> To: Brian Z Ring
> Cc: r-help at r-project.org
> Subject: Re: [R] package metafor: error when setting 'col' and 'at' for a
> forest plot
> 
> 
> On Jan 4, 2013, at 9:13 PM, Brian Z Ring wrote:
> 
> > I am using metafor to create forest plots. This code gives me the
> > expected plot (setting x axis tick marks):
> >
> > forest(forest$OR, ci.lb=forest$Low, ci.ub=forest$High,  at=log(c(.
> > 05, .25,
> > 1, 10)), slab=forest$SNP, atransf=exp)
> >
> > As does this (setting colors):
> >
> > forest(forest$OR, ci.lb=forest$Low, ci.ub=forest$High,  col=c(1,2,3),
> > slab=forest$SNP, atransf=exp)
> >
> > But if I try to set both 'at' and 'col':
> >
> > forest(forest$OR, ci.lb=forest$Low, ci.ub=forest$High,  col=c(1,2,3),
> > at=log(c(.05, .25, 1, 10)), slab=forest$SNP, atransf=exp)
> >
> > I receive this error:
> > Error in polygon(x = c(alim[2], alim[2] - (1.4/100) * cex * (xlim[2]
> > -  :
> >  formal argument "col" matched by multiple actual arguments
> >
> > Any help greatly appreciated.
> 
> Can you reproduce this using the examples in the package help pages?
> 
> --
> 
> David Winsemius, MD
> Alameda, CA, USA
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list