Creates a forest plot with ggplot

make_forest_plot(
  panels,
  row.labels = NULL,
  row.labels.levels = c("heading1", "heading2", "heading3"),
  rows = NULL,
  exponentiate = TRUE,
  logscale = exponentiate,
  panel.names = NULL,
  panel.headings = panel.names,
  col.key = "key",
  col.estimate = "estimate",
  col.stderr = "stderr",
  col.lci = NULL,
  col.uci = NULL,
  col.left = NULL,
  col.right = NULL,
  col.right.parse = FALSE,
  col.left.heading = "",
  col.right.heading = "HR (95% CI)",
  col.left.pos = NULL,
  col.right.pos = NULL,
  col.left.hjust = 1,
  col.right.hjust = 0,
  col.heading.space = 0,
  estcolumn = TRUE,
  col.keep = NULL,
  ci.delim = ", ",
  digits = 2,
  title = "",
  xlab = "HR (95% CI)",
  xlim = NULL,
  xticks = NULL,
  nullval = NULL,
  blankrows = c(1, 1, 0, 0),
  col.diamond = NULL,
  diamond = NULL,
  col.bold = NULL,
  bold.labels = NULL,
  scalepoints = FALSE,
  minse = NULL,
  pointsize = 3,
  shape = NULL,
  plotcolour = "black",
  colour = NULL,
  cicolour = colour,
  fill = NULL,
  ciunder = NULL,
  addtext = NULL,
  left.space = NULL,
  right.space = NULL,
  mid.space = unit(5, "mm"),
  plot.margin = margin(8, 8, 8, 8, "mm"),
  panel.width = NULL,
  base_size = 11,
  base_line_size = base_size/22,
  stroke = 0,
  printplot = TRUE,
  showcode = TRUE,
  addcode = NULL,
  addaes = NULL,
  addarg = NULL,
  envir = NULL,
  cols = panels,
  headings = NULL,
  colnames = NULL,
  colheadings = colnames,
  boldheadings = NULL,
  heading.space = NULL,
  panel.space = NULL,
  label.space = NULL,
  plot.space = NULL,
  col.right.space = NULL,
  col.left.space = NULL,
  margin = NULL,
  units = NULL
)

Arguments

panels

A list of data frames. These should include columns or point estimates, and standard errors or confidence interval limits. If you specify a row.labels data frame, then they must also all contain a key column with the same name (which can be specified by col.key).

row.labels

A data frame that contains the labels to be used for the rows of the plot. Use NA if a lower level heading is not required for a given row.

row.labels.levels

A character vector up to length 3. The names of columns in row.labels to use as headings/subheadings/labels for labelling rows. (Default: c("heading1", "heading2", "heading3"))

rows

A character vector. The top level labels of rows to be included in the plot.

exponentiate

Exponentiate estimates (and CIs) before plotting. (Default: TRUE)

logscale

Use log scale on the axis, and add a line at null effect. (Default: exponentiate)

panel.names

A character vector. The names to be used for each forest plot panel. If none provided, then they will be numbered 1, 2, 3 ...

panel.headings

Titles to be placed above each forest plot. (Default: panel.names)

col.key

Name of column that links the results given in each data frame provided in panels and the labels given in row.labels.

If row.labels data frame is not given, then this column will be used as row labels.

(Default: "key")

col.estimate

Name of column that provides point estimates. (Default: "estimate")

col.stderr

Name of column that provides standard errors. (Default: "stderr")

col.lci

Name of column that provides lower limit of confidence intervals.

col.uci

Name of column that provides upper limit of confidence intervals.

col.left

Names of columns to be printed to the left of the plot.

col.right

Names of columns to be printed to the right of the plot.

col.right.parse

A logical vector, the same length as col.right (+ 1 if estcolumn = TRUE). Should the contents of the columns be parsed into expressions. (Default: All FALSE, except estcolumn.)

col.left.heading

A character vector of titles for col.left columns. (Default: "")

col.right.heading

A character vector of titles for the column of estimates (if estcolumn = TRUE) and col.right columns. (Default: "HR (95% CI)")

col.left.pos

A unit vector to position col.right columns.

col.right.pos

A unit vector to position col.right columns.

col.left.hjust

A numeric vector. The horizontal justification of col.left columns. (Default: 1)

col.right.hjust

A numeric vector. The horizontal justification of col.right columns. (Default: 0)

col.heading.space

Position of the titles given by col.left.heading and col.right.heading. Increase to move them up. (Default: 0)

estcolumn

Include column of estimates and confidence intervals to the right of each plot. (Default: TRUE)

col.keep

Names of additional columns to be kept in returned data frame.

ci.delim

Character string to separate lower and upper limits of confidence interval. (Default: ", ")

digits

Number of digits after decimal point to show for estimates and confidence intervals. (Default: 2)

title

Title to appear at the top of the plot.

xlab

Label to appear below the x-axis. (Default: "HR (95% CI)")

xlim

A numeric vector. The limits of the x axis.

xticks

A numeric vector. The tick points of the x axis.

nullval

Add a vertical reference line at this value. (If logscale == TRUE then by default it will be added at 1, but use NA not to plot this line.)

blankrows

A numeric vector of length 4 specifying the number of blank rows after a heading1, at the end of a heading1 'section', after a heading2, and at the end of a heading2 'section. (Default: c(1, 1, 0, 0))

col.diamond

Plot estimates and CIs as diamonds. Name of a column of logical values.

diamond

Alternative to col.diamond. A character vectors identify the rows (using the key values) for which the estimate and CI should be plotted using a diamond.

col.bold

Plot text as bold. Name of a column of logical values.

bold.labels

A character vector identifying row labels (using key values) which should additionally be bold. (Default: NULL)

scalepoints

Should the points be scaled by inverse of the standard error? (Default: FALSE)

minse

Minimum standard error to use when scaling point size. (Default will use minimum in the data.)

pointsize

The (largest) size of box to use for plotting point estimates. (Default: 3)

shape

Shape of points. An integer, or name of a column of integers. (Default will use shape 22 - squares with fill.)

plotcolour

Colour for all parts of the plot. (Default: "black")

colour

Colour of points. Name of a colour, or name of a column of colour names. (Default will use plotcolour.)

cicolour

Colour of CI lines. Colour of CI lines. Name of a colour, or name of a column of colour names. (Default will use plotcolour.)

fill

Fill colour of points. Fill colour of points. Name of a colour, or name of a column of colour names. (Default will use plotcolour.)

ciunder

Plot CI lines before points. A logical value, or name of a column of logical values. (Default will plot CI lines after points.)

addtext

A list of data frames. List must be the same length as panels. Data frames should contain a column with the name specified in col.key, and one or more of:

1. a column named 'text' containing character strings

2. columns named 'het_dof', 'het_stat', and 'het_p' containing character strings

3. columns names 'trend_stat' and 'trend_p' containing character strings

The character strings, heterogeneity test, and trend test results will be plotted in the column of estimates and CIs, below the row with the key given in the col.key column.

left.space

Size of gap to leave to the left of panels. (Default: 1 + 2*length(col.left))

right.space

Size of gap to leave to the right of panels. (Default: 5 + 2*length(col.right))

mid.space

Size of additional gap to leave between panels. (Default: unit(5, "mm"))

plot.margin

Plot margin, given as margin(top, right, bottom, left, units). (Default: margin(8, 8, 8, 8, "mm"))

panel.width

Panel width to assume and apply different formatting to narrow CIs. Unit is "mm".

base_size

base font size, given in pts.

base_line_size

base size for line elements

stroke

Size of outline of shapes. (Default: 0)

printplot

Print the plot. (Default: TRUE)

showcode

Show the ggplot2 code to generate the plot in RStudio 'Viewer' pane. (Default: TRUE)

addcode

A character vector of code to add to the generated code. The first element should be a regular expression. The remaining elements are added to the generated code just before the first match of a line (trimmed of whitespace) with the regular expression. (Default: NULL)

addaes

Specify additional aesthetics for some ggplot layers.

addarg

Specify additional arguments for some ggplot layers.

envir

Environment in which to evaluate the plot code. May be useful when calling this function inside another function.

cols

DEPRECATED.

headings

DEPRECATED.

colnames

DEPRECATED.

colheadings

DEPRECATED.

boldheadings

DEPRECATED.

heading.space

DEPRECATED. Even older method for specifying spacing.

panel.space

DEPRECATED. Old method for specifying spacing.

label.space

DEPRECATED. Old method for specifying spacing.

plot.space

DEPRECATED. Even older method for specifying spacing.

col.right.space

DEPRACTED

col.left.space

DEPRACTED

margin

DEPRECATED. Old method for specifying margins.

units

DEPRECATED

Value

A list:

plot

the plot

code

ggplot2 code to generate the plot

Details

The function returns the plot and ggplot2 code to create the plot. In RStudio, the ggplot2 code will be shown in the viewer.