This package provides functions to create contour-enhanced forest plots for continuous and binary outcomes in meta-analysis, including options for prediction intervals, customized colors, and study labeling. Based on ‘metafor’ and ‘ggplot2’
Note: Make sure your dataset has the correct column names:
- Continuous outcomes:mean_t,n_t,sd_t,mean_c,n_c,sd_c
- Binary outcomes:events_t,n_t,events_c,n_c
Functionsforest_cont()andforest_bin()require these labels to run correctly.
library(contourforest)
# run contour forest plot for binary data
forest_bin(
dat = bcg(),
measure = "OR",
xlab = "Odds Ratio",
title = "BCG Vaccine Meta-analysis",
tlim = c(0, 2.3),
contour_left_min = c(0,0.3,0.5,0.7),
contour_left_max = c(0.3,0.5,0.7,1),
contour_right_min = c(1,1.2,1.5,1.8),
contour_right_max = c(1.2,1.5,1.8,2.5)
)
## `height` was translated to `width`.
## `height` was translated to `width`.
# Subgroup Forest Plot for Binary Outcome Meta-analysis
forest_bin_subgroup(
dat = bcg(), # data
subgroup = " subgroup", # subgroup name
tlim = c(0, 2.3), # truncation limit to prevent extension of line beyond shaded #areas
contour_left_min = c(0, 0.3, 0.5, 0.7),
contour_left_max = c(0.3, 0.5, 0.7, 1),
contour_right_min = c(1, 1.2, 1.5, 1.8),
contour_right_max = c(1.2, 1.5, 1.8, 2.4)
)
## `height` was translated to `width`.
## `height` was translated to `width`.
forest_cont(
dat1,
measure = "MD",
xlab = "Mean Difference",
study_x = -9,
sort = "effect",
hetero_x = -12,
treatment_x = -7,
control_x = -5,
effect_x = 5.5,
weight_x = 10,
PredInt_x = 7
)
## `height` was translated to `width`.
## `height` was translated to `width`.
forest_cont(
dat1,
measure = "SMD",
xlab = "Standardized Mean Difference",
hetero_x = -9.9,
study_x = -7,
sort = "effect",
treatment_x = -5,
control_x = -3,
effect_x = 2.5,
weight_x = 4,
PredInt_x = 4
)
## `height` was translated to `width`.
## `height` was translated to `width`.
forest_cont_subgroup(dat1,
subgroup_col = "subgroup"
)
## `height` was translated to `width`.
## `height` was translated to `width`.
# taking data from the published paper
# https://doi.org/10.1093/ejo/cjad053
df <- data.frame(
study = c("Ulger 2006", "Cook 1994", "Zervas 2016", "Haralabakis 2003"),
year = c(2006, 1994, 2016, 2003),
n.e = c(12, 30, 22, 30),
mean.e = c(0.67, -0.28, -1.13, 24.9),
sd.e = c(0.65, 1.35, 1.69, 5.2),
n.c = c(12, 30, 19, 22),
mean.c = c(0.58, -0.63, -0.09, 23.4),
sd.c = c(0.79, 1.46, 1.89, 4.2)
)
# rename variable as required in forest_cont() function
colnames(df) <- c("Study", "year", "n_t", "mean_t", "sd_t", "n_c", "mean_c", "sd_c")
# 'S' is capital in study
# make sure either your data in excel have these labels ("Study", "year", "n_t", "mean_t", "sd_t", "n_c", "mean_c", "sd_c")or change to this
# run function
forest_cont(df,
sort = "effect")
## `height` was translated to `width`.
## `height` was translated to `width`.
# modfify various parameter position to make it more attactive
forest_cont(df,
title = "FMA of cervical Headgear vs \n control group",
hetero_x = -9, # position heterogeneity statistics like I^2 etc
study_x = -7.5, # postion study label on x-axis
treatment_x = -5.5,# postion trt group(mean[sd]) label on x-axis
control_x = -4,
sort = "effect", # arrange study by treatment effect level
effect_x = 2.6, # position SMD or MD on x-axis
weight_x = 5, # position wieght on x-axis
PredInt_x = 2.6, # position prediciton interval on x-axis
contour_left_min = c(-2, -0.5, -0.2, 0), # change shade on left
contour_left_max = c(-0.5, -0.2, 0, 0.2),
contour_right_min = c(0, 0.2, 0.5, 0.8),
contour_right_max = c(0.2, 0.5, 0.8, 2.5),)# change shade on right
## `height` was translated to `width`.
## `height` was translated to `width`.
# changing color
forest_cont(df,
title = "FMA of cervical Headgear vs \n control group",
study.col = "#fcba03", # change study (square) color
CI.col = "black", # change confident interval (line on square) colr
diamond.col = "blue", # change diamond color
Pred.Inter.col = "darkgreen", # change prediciton interval color
hetero_x = -9,
study_x = -7.5,
treatment_x = -5.5,
control_x = -4,
sort = "effect",
effect_x = 2.6,
weight_x = 5,
PredInt_x = 2.6,
contour_left_min = c(-2, -0.5, -0.2, 0),
contour_left_max = c(-0.5, -0.2, 0, 0.2),
contour_right_min = c(0, 0.2, 0.5, 0.8),
contour_right_max = c(0.2, 0.5, 0.8, 2.5),)
## `height` was translated to `width`.
## `height` was translated to `width`.