5

I'm trying to make a forest plot in R using the meta::forest() function, and am having formatting issues when trying to change the left columns. The overall effect statistics disappear, and the 'author' column becomes centre aligned.

Here is an example of what the forest plot looks like when I don't change the left column names:

Original Forest Plot enter image description here

As you can see down the very bottom of each 'Subgroup' and for the Overall effect, statistics are shown.However, when I try to change the left columns to 'Author' and 'Measure' by adding the a line to my code 'leftcols( )', these statistics are removed and the columns become centre aligned:

Forest Plot with Errors enter image description here

Specifically, what I'd like help with is:

  • Changing the left column names to 'Author' and 'Measure' without removing the overall statistics
  • Keeping the columns left aligned
  • Increasing the gaps between each of the columns to improve readability

Code for a reproducible example:

ForestPlot <- data.frame(
      stringsAsFactors = FALSE,
                Author = c("Author1","Author2","Author3",
                           "Author4","Author5","Author6","Author7","Author8",
                           "Author9","Author10","Author11","Author12","Author13",
                           "Author14","Author15","Author16","Author17",
                           "Author18","Author19","Author20","Author21","Author22",
                           "Author23","Author24","Author25","Author26","Author27",
                           "Author28","Author29","Author30","Author31","Author32",
                           "Author33"),
                    TE = c(-0.816425,-1.6769,-0.1843,
                           0.2024333,0.6572,-1.2798,-0.3335,-3.3999,-0.7975,
                           -0.2593,-0.1745,-0.1681,-0.816425,-1.7009,-0.2606,
                           -0.2007,-1.1554,-0.2615,-0.8014,-0.2953,-1.0333,-0.7091,
                           0.2301,-0.8444,-0.1545,-0.7629,-1.0476,-0.354,
                           0.0736,-0.4139,0.1353,-0.918,-0.384),
                  seTE = c(0.250827211,0.3012,0.3034,
                           0.3539,0.2456,0.212,0.1861,0.4002,0.2711,0.2964,
                           0.3251,0.325,0.250827211,0.371,0.196,0.2527,0.2363,
                           0.2246,0.2806,0.2844,0.2753,0.3112,0.3173,0.4287,
                           0.4089,0.324,0.3381,0.2242,0.2756,0.2041,0.177,0.3849,
                           0.2828),
                   var = c(0.06291429,0.09072144,
                           0.09205156,0.06713355,0.06031936,0.044944,0.03463321,
                           0.16016004,0.07349521,0.08785296,0.10569001,0.105625,
                           0.06291429,0.137641,0.038416,0.06385729,0.05583769,
                           0.05044516,0.07873636,0.08088336,0.07579009,0.09684544,
                           0.10067929,0.18378369,0.16719921,0.104976,0.11431161,
                           0.05026564,0.10556001,0.04165681,0.031329,0.14814801,
                           0.07997584),
              Subgroup = c("Group1","Group1","Group2",
                           "Group2","Group2","Group1","Group2","Group1","Group2",
                           "Group2","Group2","Group1","Group2","Group1",
                           "Group1","Group2","Group1","Group2","Group1","Group2",
                           "Group1","Group2","Group2","Group2","Group2","Group2",
                           "Group2","Group2","Group1","Group2","Group1",
                           "Group1","Group1"),
               Measure = c("ER","ER","ER","ER","ER",
                           "ER","ER","ER","ER","ER","ER","ER","ER","ER","ER",
                           "ER","ER","ER","ER","ER","ER","ER","ER","ER",
                           "ER","ER","ER","ER","ER","ER","ER","ER","ER")
    )

library(meta)
library(metafor)

#Initial Random Effect Analysis - required for production of Forest Plot

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

#Updating this random effects model to sort by subgroup 

forest.subgroup<-update.meta(Forest.Analysis, 
                               byvar=Subgroup, 
                               comb.random = TRUE, 
                               comb.fixed = FALSE)
forest.subgroup

#Original forest plot which includes overall statistic at the bottom (for reference)

forest(forest.subgroup,
       sortvar = TE,
       xlim = c(-4.5,2),
       studylab = "Author",
       rightlabs = c("g","95% CI","weight"),
       hetstat = TRUE,
       addrow.overall = TRUE,
       pooled.totals = FALSE,
       smlab = "Emotion Recognition Accuracy",
       text.random = "Overall effect",
       overall = TRUE,
       comb.random = TRUE,
       print.tau2 = FALSE,
       print.I2 = TRUE,
       print.I2.ci = TRUE,
       col.diamond = "blue",
       col.diamond.lines = "black",
       col.predict = "black",
       prediction = TRUE)

#Forest plot when I try to change left columns

forest(forest.subgroup,
       sortvar = TE,
       xlim = c(-4.5,2),
       studylab = "Author",
       rightlabs = c("g","95% CI","weight"),
       leftcols = c("Author", "Measure"),
       hetstat = TRUE,
       addrow.overall = TRUE,
       pooled.totals = FALSE,
       smlab = "Emotion Recognition Accuracy",
       text.random = "Overall effect",
       overall = TRUE,
       comb.random = TRUE,
       print.tau2 = FALSE,
       print.I2 = TRUE,
       print.I2.ci = TRUE,
       col.diamond = "blue",
       col.diamond.lines = "black",
       col.predict = "black",
       prediction = TRUE)

#sessionInfo output
#R version 3.5.3 (2019-03-11)
#Platform: x86_64-apple-darwin15.6.0 (64-bit)
#Running under: macOS Mojave 10.14.6

#locale:
 # [1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8

#attached base packages:
 # [1] stats     graphics  grDevices utils     datasets  methods   base     

#other attached packages:
  #[1] metafor_2.1-0 Matrix_1.2-15 meta_4.9-9    readr_1.3.1  

#loaded via a namespace (and not attached):
  #[1] Rcpp_1.0.1      lattice_0.20-38 zeallot_0.1.0   crayon_1.3.4   
#[5] grid_3.5.3      R6_2.4.0        nlme_3.1-137    backports_1.1.3
#[9] pillar_1.4.3    rlang_0.4.2     rstudioapi_0.10 vctrs_0.2.1    
#[13] tools_3.5.3     hms_0.5.3       yaml_2.2.0      compiler_3.5.3 
#[17] pkgconfig_2.0.2 tibble_2.1.3 

Thanks in advance for your help.

Tung
  • 26,371
  • 7
  • 91
  • 115
lhan
  • 51
  • 3
  • Welcome to SO, Lauren! You say you need help modifying code, but you've not provided any code or what's wrong with what is happening. Please make this question a little more reproducible by including sample code you've attempted (including listing non-base R packages, and any errors/warnings received) and intended output. Refs: https://stackoverflow.com/questions/5963269, [mcve], and https://stackoverflow.com/tags/r/info. – r2evans Mar 30 '20 at 00:02
  • 2
    @r2evans thanks for your response! I am new to this so I may be misunderstanding, but I followed the minimal reproducible examples when posting this question. I posted enough code to completely reproduce the forest plots and for people to be able to see the code I've used so far. I've added a bit more information to the question to improve clarity and some pictures that show the issues - I hope this helps. Let me know if I'm misunderstanding! – lhan Mar 30 '20 at 00:28

1 Answers1

0

I have also encountered this issue when adding left columns in metafor or meta forest plots. I do not believe there is a way to fix this in the conventional use of the plotting functions (I would love to be wrong).

The metaviz package gives you a little more control with forest plot functions that wrap ggplot. You might be able to achieve your aims more easily in that package.

Thomas Luechtefeld
  • 1,316
  • 15
  • 23