Skip to contents

This function renders a graphical representation of causal effect estimates, organised by effect size on either the risk difference (RD) or risk ratio (RR) scale. It categorises estimates into "positive", "negative", or "zero_crossing" based on their confidence intervals. The function features advanced customisability for graphical parameters, including error bar width and the application of custom ggplot2 themes. Notably, it avoids direct manipulation of the input data and implements an advanced labelling strategy for the x-axis to prevent incoherent negative values for RR.

Usage

margot_plot(
  .data,
  type = c("RD", "RR"),
  order = c("default", "alphabetical"),
  title,
  subtitle,
  estimate_scale = 1,
  base_size = 11,
  text_size = 2.75,
  point_size = 0.5,
  title_size = 10,
  subtitle_size = 9,
  legend_text_size = 6,
  legend_title_size = 6,
  x_offset = ifelse(type == "RR", 0, -1.75),
  x_lim_lo = ifelse(type == "RR", 0.1, -1.75),
  x_lim_hi = ifelse(type == "RR", 2.5, 1),
  linewidth = 0.5,
  plot_theme = NULL
)

Arguments

.data

A data frame of causal effect estimates, ideally output by a `group_tab` function or similar. The data should include confidence intervals and effect estimate values.

type

Character string indicating the scale of effect estimates: "RD" for risk difference or "RR" for risk ratio, with "RD" as the default.

order

Character string indicating the ordering of the output: "default" for default descending, "alphabetical" for alphabetical, and "custom" for custom order provided in .data.

title

Main title for the plot.

subtitle

Subtitle for the plot.

estimate_scale

Numeric multiplier to adjust the horizontal offset of estimate labels, aiding in plot clarity. Default is 1.

base_size

Base font size for the plot, applied globally unless overridden. Default is 11.

text_size

Font size for the estimate labels. Default is 2.75.

point_size

Size of points representing the estimates. Default is 0.5.

title_size

Font size for the plot title. Default is 10.

subtitle_size

Font size for the plot subtitle. Default is 9.

legend_text_size

Font size for legend text. Default is 6.

legend_title_size

Font size for legend titles. Default is 6.

x_offset

Horizontal adjustment for estimate labels, varied based on `type`. Default adjustments are 0 for "RR" and -1.75 for "RD".

x_lim_lo

Lower limit of the x-axis, automatically adjusted based on `type`.

x_lim_hi

Upper limit of the x-axis, automatically adjusted based on `type`.

linewidth

Width of the error bars in the plot. Default is 0.5.

plot_theme

ggplot2 theme object for customising plot appearance. Inherits `base_size` from `base_size` parameter to maintain consistency. Uses `theme_classic()` as default but allows for customisation.

custom_order

Optional vector specifying custom ordering if 'order' is set to 'custom'.

Value

A ggplot object displaying the causal effect estimates with categorisation and error bars. This plot is tailored for further modifications or direct usage.