5

我正在尝试使用 meta::forest() 函数在 R 中制作森林图,并且在尝试更改左列时遇到格式问题。整体效果统计消失,“作者”列居中对齐。

这是我不更改左列名称时森林图的示例:

原始森林图 在此处输入图像描述

正如您在每个“子组”的最底部看到的那样,对于整体效果,显示了统计信息。但是,当我尝试通过在我的代码中添加一行来将左列更改为“作者”和“测量”时leftcols( )',这些统计信息被删除,列居中对齐:

有错误的森林图 在此处输入图像描述

具体来说,我想要帮助的是:

  • 将左列名称更改为“作者”和“测量”而不删除整体统计信息
  • 保持列左对齐
  • 增加每列之间的间隙以提高可读性

可重现示例的代码:

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 

在此先感谢您的帮助。

4

1 回答 1

0

在 metafor 或元森林图中添加左列时,我也遇到了这个问题。我不相信在常规使用绘图功能时有办法解决这个问题(我很想弄错)。

metaviz 包让您对包装 ggplot 的森林图函数进行更多控制。在该软件包中,您也许可以更轻松地实现您的目标。

于 2021-06-30T13:44:58.960 回答