Toggle Risk Difference Columns in the AE-Specific Tables

library(forestly)
library(metalite)

The interactive AE forest plots include AE-specific tables that present both numerical and visual summaries for each AE SOC/PT term. In this vignette, we demonstrate how to toggle the visibility of risk difference columns using an interactive button.

Step 1: build your metadata

Building interactive AE forest plots starts with constructing the metadata. The detailed procedure for building metadata is covered in the vignette Generate Interactive AE Forest Plots with Drill Down to AE Listing. Therefore, in this vignette, we will skip those details and directly use the metadata created there.

adsl <- forestly_adsl
adae <- forestly_adae

adsl$TRTA <- factor(forestly_adsl$TRT01A,
  levels = c("Xanomeline Low Dose", "Placebo"),
  labels = c("Low Dose", "Placebo")
)
adae$TRTA <- factor(forestly_adae$TRTA,
  levels = c("Xanomeline Low Dose", "Placebo"),
  labels = c("Low Dose", "Placebo")
)

meta <- meta_adam(population = adsl, observation = adae) |>
  define_plan(plan = plan(
    analysis = "ae_forestly",
    population = "apat",
    observation = "apat",
    parameter = "any;drug-related"
  )) |>
  define_analysis(name = "ae_forestly", label = "Interactive Forest Plot") |>
  define_population(
    name = "apat", group = "TRTA", id = "USUBJID",
    subset = SAFFL == "Y", label = "All Patient as Treated"
  ) |>
  define_observation(
    name = "apat", group = "TRTA",
    subset = SAFFL == "Y", label = "All Patient as Treated"
  ) |>
  define_parameter(
    name = "any",
    subset = NULL,
    label = "Any AEs",
    var = "AEDECOD", soc = "AEBODSYS"
  ) |>
  define_parameter(
    name = "drug-related",
    subset = toupper(AREL) == "RELATED",
    label = "Drug-related AEs",
    var = "AEDECOD", soc = "AEBODSYS"
  ) |>
  meta_build()

Step 2: toggle risk difference columns

The numeric risk difference columns (diff) are always offered in the “Show/Hide columns” menu above the table, hidden by default unless "diff" is in the display argument of format_ae_forestly(). (The display_diff_toggle argument of ae_forestly() is deprecated and ignored.)

The display_soc_toggle = ... argument controls the SOC column: if TRUE, it is included in the table and offered in the same menu (hidden by default); if FALSE, it is left out of the table entirely. Leaving it out makes the saved HTML file slightly smaller, which only matters for very large data sets.

meta |>
  prepare_ae_forestly() |>
  format_ae_forestly(display = c("n", "prop", "fig_prop", "fig_diff", "diff")) |>
  ae_forestly(display_soc_toggle = TRUE)