0

I am trying to create a contour-enhanced funnel plot in R for a meta-analysis. A contour-enhanced funnel plot also shows the areas of the plot corresponding to different p-values (see Peters et al, 2008, Contour-enhanced meta-analysis funnel plots help distinguish publication bias from other causes of asymmetry).

I found this very useful guide to meta-analytic procedure online (https://bookdown.org/MathiasHarrer/Doing_Meta_Analysis_in_R/smallstudyeffects.html) suggesting the following code to create such a plot:

funnel(m.hksj, xlab="Hedges' g", 
       contour = c(.95,.975,.99),
       col.contour=c("darkblue","blue","lightblue"))+
legend(1.4, 0, c("p < 0.05", "p<0.025", "< 0.01"),bty = "n",
       fill=c("darkblue","blue","lightblue"))

When executing this code, the plot is produced, but without legend. The error says that there is a non-numeric argument for the binary operator. I also make sure to use specifically target the funnel() function from the meta package, as it says it in the guide, as metafor is loaded as well in my environment. Does anybody know how to fix this and create a nice legend?

Also, I tried the following code suggested by the creators of the metafor package (http://www.metafor-project.org/doku.php/plots:contour_enhanced_funnel_plot):

funnel(res, level=c(.90, .95, .99),shade=c("white", "gray55", "gray75"), refline=0, legend=TRUE)

There is a lot of warnings regarding the level argument, and it does not even produce a working funnel plot, let alone with a legend. In this case, I assumed that this is caused by the fact that I submit not a rma object, but a meta object from the meta package. On the other hand, then it should work with the first code above, but it does not.

Grateful for all suggestions!

EDIT: Here is an example based on the code provided in the guide mentioned above

data = data.frame("Author" = c("Jones", "Goldman", "Townsend", "Martin", "Rose"),
                  "TE" = c(0.23, 0.56, 0.78, 0.23, 0.33),
                  "seTE" = c(0.324, 0.235, 0.394, 0.275, 0.348),
                  "subgroup" = c("one", "one", "two", "two", "three"))

m.data <- metagen(TE,
                  seTE,
                  data = data,
                  studlab = paste(Author),
                  comb.fixed = FALSE,
                  comb.random = TRUE,
                  method.tau = "SJ",
                  hakn = TRUE,
                  prediction = TRUE,
                  sm = "SMD")

funnel(m.data, xlab="Hedges' g", 
       contour = c(.95,.975,.99),
       col.contour=c("darkblue","blue","lightblue"))+
legend(1.4, 0, c("p < 0.05", "p<0.025", "< 0.01"),bty = "n",
       fill=c("darkblue","blue","lightblue"))
fuestro
  • 45
  • 5
  • Please review how to create a [reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) example. Specifically, please include a sample of your data using `dput`, and the code you have run on it – Conor Neilson Mar 17 '21 at 04:19
  • I'm afraid `dput()` is not of much use here. The object that is submitted to `funnel` is a huge list of class `c("metagen", "meta")` that is produced by applying the `metagen()` function from the `meta` package on my data (calculated effect sizes and sampling variance). The code above is directly taken from the guide I mentioned, and the object `m.hksj` is of the same class. – fuestro Mar 19 '21 at 10:51

1 Answers1

0

You're getting the error because of the plus sign, and the legend isn't printing because the coordinates are probably outside of the range of the plot.

Try removing the plus sign and changing the coordinates of the legend, like this:

funnel(m.data, xlab="Hedges' g", 
           contour = c(.95,.975,.99),
           col.contour=c("darkblue","blue","lightblue"))
legend("topright", c("p < 0.05", "p<0.025", "< 0.01"),bty = "n",
           fill=c("darkblue","blue","lightblue"))
jmn
  • 16
  • 1
  • That was it! Thank you so much! "topright" puts it at an awkward position within the plot, but knowing the reason for the previous problem I managed to place the legend nicely - and visibly within the plot. – fuestro Apr 01 '21 at 19:31