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:
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:
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.