Skip to content

Conversation

@fukuhiro2023
Copy link
Collaborator

@fukuhiro2023 fukuhiro2023 commented Aug 13, 2024

This PR adds rtf_static_forestly() to create an RTF output based on the static forest plots.

Background:
We have already had functions to create static plots, which can be combined by patchwork to generate an AE forest plot (Article). This new function can output the plot as an RTF file. The expected inputs are metadata and static plot function calls in order to split the figure by a specified number of rows. This is designed with the consideration that if the figure created by patchwork is exported as a single image to RTF, the image may become extremely small when the number of rows is large.

Example code & output:

forestly_adsl$TRTA <- factor(
  forestly_adsl$TRT01A,
  levels = c("Xanomeline Low Dose", "Placebo"),
  labels = c("Low Dose", "Placebo")
)
forestly_adae$TRTA <- factor(
  forestly_adae$TRTA,
  levels = c("Xanomeline Low Dose", "Placebo"),
  labels = c("Low Dose", "Placebo")
)
outdata <- meta_forestly(
  dataset_adsl = forestly_adsl,
  dataset_adae = forestly_adae
) |>
  prepare_ae_forestly()|>
  format_ae_forestly()

p1 <- substitute(
  plot_dot(
    tbl,
    prop_cols = c("prop_1", "prop_2"),
    y_var = "name",
    label = c("Treatment", "Placebo")
  )
)
p2 <- substitute(
  plot_errorbar(
    tbl,
    ci_cols = c("diff_1", "lower_1", "upper_1"),
    y_var = "name",
    label = c("Treatment", "Placebo"),
    legend_nrow = NULL,
    theme = theme_panel(show_ticks = FALSE, show_text = FALSE)
  )
)
p3 <- substitute(
  table_panel(
    tbl,
    n_cols = c("n_1", "n_2"),
    prop_cols = c("prop_1", "prop_2"),
    y_var = "name",
    theme = theme_panel(show_ticks = FALSE, show_text = FALSE),
    x_label = c("Treatment \n n(%)", "Placebo \n n(%)")
  )
)
outdata |> rtf_static_forestly(
  plot_calls = c(p1, p2, p3),
  source = "Source:  [CDISCpilot: adam-adsl; adae]",
  path_outdata = tempfile(fileext = ".Rdata"),
  path_outtable =  tempfile(fileext = ".rtf")
)
2025-08-20_forestly-rtf_static_forestly

@elong0527
Copy link
Collaborator

Thanks for adding the new feature into forestly. I would suggest of adding a vignette to help user understand what's achievable.

In the PR, could you also provide an example and a screenshot of the output to help reviewer understand what can be achieved?

@fukuhiro2023
Copy link
Collaborator Author

Thanks @elong0527 for your comment. The PR description has been updated to provide background and an example of this PR, but a vignette will be added in the future.

n_rows = 25,
orientation = "portrait",
fig_size = c(6, 6),
title = c("analysis", "observation", "population"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this argument will confuse user who are not familiar with metalite.

If we only allow limited combination of title, we may consider a title_type argument with value 1, 2, 3 to clarify what it can be achieved.

If I am a user, I would infer title should allow me to customize the full title. if needed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since argument title is also used in other tlf function, should we keep the same naming convention.

https://github.com/Merck/metalite.ae/blob/2e45d26325d7eec68aac8d1b140730b68c4dcf48/R/tlf_ae_specific.R#L63

@wangben718 wangben718 merged commit 16048ac into main Sep 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants