[R-meta] Two large forest plots in one image
Emanuel Schembri
|e||d26 @end|ng |rom gm@||@com
Mon Jul 29 00:48:19 CEST 2024
Hi,
I created two (relatively large) forest plots with the meta package
and am trying to fit them on top of each other in a single image.
However, the resulting combined image with two forest plots makes the
two plots overlap, and the overlapping parts strike out.
I tried using the 1). gridExtra package to place the forest plots
above each other and 2). the as.ggplot() and then combining them via
the patchwork package, but in both instances, the forest plots
overlapped.
I managed to fit two small forest plots neatly in one image; however,
I could not do the same with large forest plots.
Any help on correctly aligning the two plots would be appreciated.
Kind regards,
Emanuel
Below are my R version and operating system:
R version 4.3.1 (2023-06-16 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)
Below is my sample data:
> dput(E1)
structure(list(study = c("Barratt", "Carli", "Gupta", "Taqi",
"Chen", "Hübner", "Zutshi", "Park", "Klotz", "Mohamad", "Chen",
"Tsui"), year = c(2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000,
2000, 2000, 2000, 2000), ev.EZ = c(1, 3, 1, 1, 0, 2, 0, 1, 1,
0, 0, 0), n.EZ = c(55, 41, 60, 9, 26, 65, 31, 25, 21, 28, 25,
57), ev.PPA = c(1, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0), n.PPA = c(55,
42, 60, 11, 27, 57, 28, 22, 21, 28, 25, 54), TRX = c(1, 2, 1,
1, 1, 1, 1, 2, 2, 2, 2, 2), TIME = c("Update", "Update", "Update",
"Old", "Old", "Old", "Old", "Old", "Old", "Old", "Old", "Old"
)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-12L))
> dput(E2)
structure(list(study = c("Steinberg", "Parker", "Madej", "Schumann",
"Carli", "Tsui", "Xu", "Park", "Cho", "Xu", "Yosunkaya", "Mann",
"Jayr", "Aceto"), year = c(2000, 2000, 2000, 2000, 2000, 2000,
2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000), ev.EZ = c(8,
3, 6, 16, 10, 10, 4, 11, 7, 5, 16, 30, 16, 2), n.EZ = c(51, 55,
41, 60, 20, 31, 20, 51, 20, 36, 21, 57, 38, 20), ev.PPA = c(9,
11, 8, 27, 11, 10, 3, 3, 9, 11, 17, 29, 14, 0), n.PPA = c(51,
55, 42, 60, 20, 33, 21, 48, 10, 32, 21, 54, 46, 19), TRX = c(2,
1, 1, 2, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2), TIME = c("Update", "Update",
"Update", "Update", "Old", "Old", "Old", "Old", "Old", "Old",
"Old", "Old", "Old", "Old")), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -14L))
Below is my code:
M3 <- metabin(ev.EZ,
n.EZ,
ev.PPA,
n.PPA,
data = E1,
studlab = paste0(study, " (", year, ")"),
sm = "RR",
method = "MH",
subgroup = TIME,
sortvar = year)
M4 <- metabin(ev.EZ,
n.EZ,
ev.PPA,
n.PPA,
data = E1,
studlab = paste0(study, " (", year, ")"),
sm = "RR",
method = "MH",
subgroup = TRX,
sortvar = year)
forest(M3,
common = FALSE,
test.overall.random=TRUE,
prediction=TRUE,
print.Q=TRUE,
print.Q.pval=TRUE,
just = "right",
layout = "RevMan5",
pooled.events=TRUE)
forest_grob1 <- grid.grab()
forest(M4,
common = FALSE,
test.overall.random=TRUE,
prediction=TRUE,
print.Q=TRUE,
print.Q.pval=TRUE,
just = "right",
layout = "RevMan5",
pooled.events=TRUE)
forest_grob2 <- grid.grab()
# Convert grobs to ggplot objects
forest_plot1 <- as.ggplot(forest_grob1)
forest_plot2 <- as.ggplot(forest_grob2)
# Arrange the ggplot objects using patchwork
combined_plot <- forest_plot1 + forest_plot2 + plot_layout(ncol = 1)
combined_plot
More information about the R-sig-meta-analysis
mailing list