Can datapoints be colored in Funnel Plot based on category in Metafor package/R?

832 Views Asked by At

Is it possible to color the datapoints in the Funnel plot? I am using the metafor package.

 # Load package
 library(metafor)

 # Load data
 data(dat.bcg)

 # Code 
 ex <- rma(ai=tpos, bi=tneg, ci=cpos, 
 di=cneg, data=dat.bcg, measure="OR",
 slab=paste(author, year, sep=", "), method="FE")

# Funnel plot
funnel(ex, transf = exp, ylab="Test group", xlab="Control")

Would it be possible to color the points based on a variable?

Fx blue colored datapoints that represent:

dat.bcg$alloc==random

Thank you, C.

1

There are 1 best solutions below

3
On BEST ANSWER

I examined the source code for the funnel method and irritatingly, no, you cannot pass a vector of colors to the col argument.

An easy workaround is to assign the output of funnel() to a variable, which will give you the x and y coordinates of the points in the funnel plot, then plot over the original points on the funnel plot with colored points.

# Create vector of colors
my_colors <- c('red','blue')[(dat.bcg$alloc == 'random') + 1]

# Create funnel plot, catching output
funnelplotdata <- funnel(ex, transf = exp, ylab="Test group", xlab="Control")

# Plot over points
with(funnelplotdata, points(x, y, col = my_colors, pch = 19))

enter image description here