Search code examples
rr-forestplotmetafor

metafor:Forest removing or moving metaestimate column


I am attempting to change the format of my forest plot to prepare for publication.

I would like to move the far right hand column that shows the effect estimate currently (in my case odds ratios). Is this column fixed to the right hand side of plot or can it be moved so that it aligns with the other columns and the forest plot itself is on the far right hand side.

This is my current forest plot code

# Forest plot of odds ratio
options(na.action = "na.pass")
forest(res.or,
       addpred=TRUE, header=TRUE,
       atransf=exp,
       order = ormri$year,
       xlim = c(-22,10),
       ilab=cbind(m1$hiv, m1$con, m1$diffci),
       ilab.xpos=c(-14, -10, -5),
       ilab.pos = 2,
       mlab = "",
       digits = 2, cex = 0.75,
       col = "blue",
       xlab = c("Odds Ratio"),
       at=log(c(0.1, .25, 1, 10, 100))) 
text(c(-15.5, -11.5, -6.5), 16.5, c("LGE+/N (%)", "LGE+/N (%)", "Diff [95% CI]"), cex=0.75)
text(c(-15.5, -11.5), 17.5, c("HIV+", "HIV -"), font =2, cex = 0.75)
## add text with Q-value, dfs, p-value, and I^2 statistic
text(-22, -1, pos=4, cex=0.75, bquote(paste("RE Model (Q = ",
                                              .(formatC(res.or$QE, digits=2, format="f")), ", df = ", .(res.or$k - res.or$p),
                                              ", p = ", .(formatC(res.or$QEp, digits=2, format="f")), "; ", I^2, " = ",
                                              .(formatC(res.or$I2, digits=1, format="f")), "%)")))

Which gives this plot forest

I would like to move the ODDS RATIO column to be alongside the diff[95 CI] column.


Solution

  • Somebody asked me a while ago to make it possible to adjust the position of the study labels (on the left) and the annotations (on the right). For this, I have added the textpos argument. See:

    https://wviechtb.github.io/metafor/reference/forest.rma.html#additional-arguments-1

    Using this example, I can illustrate how to make use of this. Swap out the forest() and text() parts with this:

    ### forest plot with extra annotations
    forest(res, atransf=exp, at=log(c(.05, .25, 1, 4)), xlim=c(-20,2),
           ilab=cbind(tpos, tneg, cpos, cneg), ilab.xpos=c(-14,-12,-10,-8), 
           cex=.75, header="Author(s) and Year", mlab="", textpos=c(-20,-3))
    op <- par(cex=.75, font=2)
    text(c(-14,-12,-10,-8), 15, c("TB+", "TB-", "TB+", "TB-"))
    text(c(-11,-9),     16, c("Vaccinated", "Control"))
    par(op)
     
    ### add text with Q-value, dfs, p-value, and I^2 statistic
    text(-20, -1, pos=4, cex=0.75, bquote(paste("RE Model (Q = ",
         .(formatC(res$QE, digits=2, format="f")), ", df = ", .(res$k - res$p),
         ", p = ", .(formatC(res$QEp, digits=2, format="f")), "; ", I^2, " = ",
         .(formatC(res$I2, digits=1, format="f")), "%)")))
    

    and voila, the annotations are to the left of the actual forest plot. It's a bit of pain to find good values for xlim, ilab.xpos, and textpos to make everything look nice (within the actual dimensions of the plotting device), but it seems like you've already spent some time dealing with this, so now you just have go through that process once more.