Skip to content
Prev 2650 / 5632 Next

[R-meta] Add a reference/citation number to author name in forest plot

Hi Dylan,

Depends to what extent you want to do this 'manually'. Here is an example:

library(metafor)
dat <- dat.bcg

labs <- paste(dat$author, dat$year)
labs[1] <- expression(paste("Aronson,", plain()^1, " 1948"))

res <- rma(ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat, measure="RR", method="REML")
forest(res, slab = labs)

So here I am 'hardcoding' the author, reference number, and year number for the first study and the same could be done for the others. If you don't have a lot of studies, then this could be done by hand.

If you want to do this 'programmatically', it gets a bit more tricky, because you have to substitute values, plus generate an expression that can be used for 'math plotting'. A bit of a nightmarish solution would be:

labs <- mapply(function(x,y,z) as.expression(bquote(.(x)^.(y)*","~.(z))), dat$author, dat$trial, dat$year)
forest(res, slab = labs)

Best,
Wolfgang