Skip to contents

Create a Margot plot for visualising causal effects with flexible sorting, embed a compact interpretation, and return a transformed table.

Usage

margot_plot(
  .data,
  type = c("RD", "RR"),
  order = c("alphabetical", "magnitude_desc", "magnitude_asc", "evaluebound_desc",
    "evaluebound_asc", "custom", "default"),
  custom_order = NULL,
  title_binary = NULL,
  include_coefficients = TRUE,
  standardize_label = c("NZ", "US", "none"),
  interpret_all_E_gt1 = FALSE,
  e_val_bound_threshold = 1,
  ...,
  options = list(),
  label_mapping = NULL,
  save_output = FALSE,
  use_timestamp = FALSE,
  base_filename = "margot_plot_output",
  prefix = NULL,
  save_path = here::here("push_mods"),
  original_df = NULL,
  bold_rows = FALSE,
  rename_cols = FALSE,
  col_renames = list(`E-Value` = "E_Value", `E-Value bound` = "E_Val_bound"),
  rename_ate = FALSE
)

Arguments

.data

a data frame with: - `outcome` column, - effect columns: `E[Y(1)]-E[Y(0)]` or `E[Y(1)]/E[Y(0)]`, - confidence limits: `2.5 - `E_Value`, `E_Val_bound`, and optional `unit`.

type

one of `"RD"` (risk difference) or `"RR"` (risk ratio). Default: `"RD"`.

order

outcome sorting. Options: - `alphabetical`, `magnitude_desc`, `magnitude_asc`, - `evaluebound_desc`, `evaluebound_asc`, `custom`, `default`. Default: `"alphabetical"`.

custom_order

character vector for `order = "custom"`.

title_binary

optional title for binary plots.

include_coefficients

logical; include effect values on plot. Default: `TRUE`.

standardize_label

one of `"NZ"`, `"US"`, or `"none"`. Default: `"NZ"`.

interpret_all_E_gt1

logical; if `TRUE`, interpret all effects with `E_Value > 1` & `E_Val_bound > 1`. Default: `FALSE`.

e_val_bound_threshold

numeric; minimum `E_Val_bound` to treat an effect as reliable. Default: `1`.

...

additional args passed to `options`.

options

list of plot & label options.

label_mapping

named vector mapping original to display labels.

save_output

logical; if `TRUE`, save output via `here_save_qs()`. Default: `FALSE`.

use_timestamp

logical; append timestamp to filename. Default: `FALSE`.

base_filename

base of output filename. Default: `"margot_plot_output"`.

prefix

optional filename prefix.

save_path

directory for saving. Default: `here::here("push_mods")`.

original_df

optional data frame for back-transformation.

bold_rows

logical; bold row-names above threshold. Default: `FALSE`.

rename_cols

logical; apply `col_renames`. Default: `FALSE`.

col_renames

named list mapping new = old. Default: `list("E-Value"="E_Value", "E-Value bound"="E_Val_bound")`.

rename_ate

logical; rename effect column to `"ATE"`. Default: `FALSE`.

Value

A list with: * `plot`: a `ggplot2` object * `interpretation`: markdown string * `transformed_table`: input `.data` with transformed row-names