We will here use the dessin_forest_simple
function in
the Data &
Functions page.
Download Forest_autom.R
# Data used
base_data <- data.frame(
variable = c("var1", "var2", "var3", "var4", "var5", "var6", "var7"),
mean = c(0.578, 0.165, 0.246, 0.700, 0.348, 0.139, 1.017),
lower = c(0.372, 0.018, 0.072, 0.333, 0.083, 0.016, 0.365),
upper = c(0.898, 1.517, 0.833, 1.474, 1.455, 1.209, 2.831)
)
dessin_forest_simple
functionArguments
dessin_forest_simple(
data_frame,
database with variable, mean, lower, upper columns.
name_col_var = "Variable",
desired column name with
variables.
name_col_mean = "HR (95%CI)",
desired
column name with estimates.
zero = 1,
where we want to
put the zero of the forest plot.
pos_graphique = 3,
can be equal to 1, 2, 3 or 4, localisation of the graph
print_variable = TRUE,
FALSE: remove the column with the
variable name
print_mean = TRUE,
FALSE: remove the
column with the estimate
var_color = NULL,
group
variable name to colour variable names by group
default colors are
1, 2, 3 etc it can be a vector of colors title = NULL,
to
change the name of the forestplot
IC = TRUE,
TRUE:
displays the CI in the column with the estimate.
boxsize = NULL,
Override the default box size based on
precision
digit = 2,
to round off the estimate and its
confidence interval.
lwd.ci = 1,
confidence interval
thickness.
clip,
allows to choose the upper and lower
limits of the x-axis.
- by default: from minimum HR/OR to
maximum HR/OR
- we specify the limits: vector of size 2
with the lower bound and the upper bound
- “clip_tot”: we
display the whole graph
by = 0.5,
allows to choose the
distance between the different ticks of the x-axis.
print_pval = FALSE
TRUE : print the pvalue in the last
column
new_page = TRUE
TRUE : If you want the plot to
appear on a new blank page
favors,
vector with the
names to display below axis for directional difference (optional)
favors_fontsize = 15,
fontsize for the text display below
axis for directional difference
y_favors_arrow,
coordinate for favors arrows (optional)
y_favors_text,
coordinate for favors labels (optional)
)
dessin_forest_simple(base_data, name_col_var = "Parameter", name_col_mean = "HR",
zero = 1, IC = FALSE, digit=2, lwd.ci=2, clip=NULL, by=0.5)
set.seed(1234)
base_data$group <- sample(c("group1", "group2"), replace=T, nrow(base_data))
dessin_forest_simple(base_data, name_col_var = "Parameter", name_col_mean = "HR", var_color = "group",
zero = 1, IC = FALSE, digit=2, lwd.ci=2, clip=NULL, by=0.5)
## [1] "colors : group1 = 1; group2 = 2"
set.seed(1234)
base_data$group <- sample(c("darkgreen", "black"), replace=T, nrow(base_data))
dessin_forest_simple(base_data, name_col_var = "Parameter", name_col_mean = "HR", var_color = "group",
zero = 1, IC = FALSE, digit=2, lwd.ci=2, clip=NULL, by=0.5)
This document is a work of the statistics team in the Biostatistics and Medical Information Department at Saint-Louis Hospital in Paris (SBIM).
Developed and updated by Noémie Bigot and Anouk Walter-Petrich
noemie.bigot@aphp.fr; anouk.walter-petrich@u-paris.fr
Based on The R Graph Gallery by Yan Holtz.