Skip to contents

Visualise the top-two splits of a policy tree with scatterplots of the two split variables, points coloured by predicted action, and optional shading for non-decision regions.

Usage

margot_plot_policy_tree(
  mc_test,
  model_name,
  original_df = NULL,
  shading = TRUE,
  color_scale = NULL,
  point_alpha = 0.5,
  theme_function = theme_classic,
  title_size = 16,
  subtitle_size = 14,
  axis_title_size = 14,
  legend_title_size = 14,
  jitter_width = 0.3,
  jitter_height = 0.3,
  split_line_color = "red",
  split_line_alpha = 0.7,
  split_line_type = "dashed",
  split_line_linewidth = 0.5,
  split_label_size = 10,
  split_label_color = "red",
  custom_action_names = NULL,
  legend_position = "bottom",
  plot_selection = "both",
  remove_tx_prefix = TRUE,
  remove_z_suffix = TRUE,
  use_title_case = TRUE,
  remove_underscores = TRUE,
  label_mapping = NULL,
  shade_fill = "#6e6e6e",
  shade_alpha = 0.5
)

Arguments

mc_test

List from a multi-arm causal forest run containing $results[[model_name]]$policy_tree_depth_2 and $results[[model_name]]$plot_data.

model_name

String name of the model in mc_test$results.

original_df

Optional data.frame of original-scale variables for axis annotations.

shading

Logical; if TRUE, shade non-decision regions. Default: TRUE.

color_scale

Optional ggplot2 colour scale. Default: Okabe–Ito palette.

point_alpha

Numeric point transparency (0–1). Default: 0.5.

theme_function

ggplot2 theme function. Default: theme_classic().

title_size

Numeric plot-title text size. Default: 16.

subtitle_size

Numeric subtitle text size. Default: 14.

axis_title_size

Numeric axis-title text size. Default: 14.

legend_title_size

Numeric legend-title text size. Default: 14.

jitter_width

Numeric horizontal jitter. Default: 0.3.

jitter_height

Numeric vertical jitter. Default: 0.3.

split_line_color

Colour of split lines. Default: "red".

split_line_alpha

Alpha for split lines. Default: 0.7.

split_line_type

Linetype for split lines. Default: "dashed".

split_line_linewidth

Linewidth for split lines. Default: 0.5.

split_label_size

Text size for secondary-axis labels. Default: 10.

split_label_color

Colour for secondary-axis labels. Default: "red".

custom_action_names

Optional vector of custom action labels.

legend_position

Legend position: "top","bottom","left","right". Default: "bottom".

plot_selection

Which panels to show: "both","p1","p2". Default: "both".

remove_tx_prefix

Logical; strip "tx_" from names. Default: TRUE.

remove_z_suffix

Logical; strip "_z" from names. Default: TRUE.

use_title_case

Logical; convert labels to Title Case. Default: TRUE.

remove_underscores

Logical; remove underscores. Default: TRUE.

label_mapping

Named list of label overrides. Default: NULL.

shade_fill

Fill colour for shading. Default: "#6e6e6e".

shade_alpha

Alpha for shading. Default: 0.35.

Value

A patchwork ggplot of the two panels.