natash
natash

Reputation: 127

Problem with naming first column in forest plot

I'm trying to create a forest plot. It all works fine so far, except that in my first column it doesn't set the author names and years (which are in the variable "ind_sample"), but "Study 1", "Study 2" and so on. I don't know how to change that so it uses the variable "ind_sample" for that.

library(metafor)
df <- read.table(header=TRUE, text="
ind_sample n cond ESxy yi vi
A&B(2019) 40 A 0.1900000 0.19233717 0.0051282051
A&B(2020) 23 A 0.2857738 0.29395814 0.0037453184
D&F(2019) 15 B 0.1800000 0.18198269 0.0108695652
E&G(2019) 89 B 0.2600000 0.26610841 0.0062111801
H&H(1997) 88 B 0.2300000 0.23418947 0.0084745763
H&U(2020) 12 B 0.2100000 0.21317135 0.0062893082
J&K(2011) 12 B 0.0600000 0.06007216 0.0090909091
L&L(2002) 13 B 0.1200000 0.12058103 0.0006381621
L&U(2020) 29 B 0.1300000 0.13073985 0.0063694268
A&D(2020) 67 C 0.0200000 0.02000267 0.0024449878
A&U(2019) 90 C 0.1600000 0.16138670 0.0049019608
A&G(2019) 93 C 0.1800000 0.18198269 0.0096153846
A&B(2019) 94 C 0.2300000 0.23418947 0.0062893082
")


res <- rma(yi, vi, data=df)



forest(res, xlim=c(-16, 4.6), at=log(c(0.05, 0.25, 1, 4)), atransf=exp,
       ilab=cbind(dat2$tpos, dat2$tneg, dat2$cpos, dat2$cneg),
       ilab.xpos=c(-9.5,-8,-6,-4.5), cex=0.75, ylim=c(-1, 27),
       order=dat$alloc, rows=c(3:4,9:15,20:23),
       mlab=mlabfun("RE Model for All Studies", res2),
       psize=1, header="Author(s) and Year")

Thank you very much!

Upvotes: 1

Views: 153

Answers (1)

Basti
Basti

Reputation: 1763

You were almost there, you can just add the slab argument with the name of studies:

forest(res, xlim=c(-16, 4.6), at=log(c(0.05, 0.25, 1, 4)), atransf=exp,
       
       slab=df$ind_sample
       
       ilab=cbind(dat2$tpos, dat2$tneg, dat2$cpos, dat2$cneg),
       ilab.xpos=c(-9.5,-8,-6,-4.5), cex=0.75, ylim=c(-1, 27),
       order=dat$alloc, rows=c(3:4,9:15,20:23),
       mlab=mlabfun("RE Model for All Studies", res2),
       psize=1, header="Author(s) and Year")

Upvotes: 1

Related Questions