Skip to content

forest plot rework#162

Merged
shajoezhu merged 39 commits intomainfrom
160_gt_forest_rework@main
Feb 27, 2026
Merged

forest plot rework#162
shajoezhu merged 39 commits intomainfrom
160_gt_forest_rework@main

Conversation

@Melkiades
Copy link
Copy Markdown
Contributor

What changes are proposed in this pull request?

  • Complete rework of forest plot function (add_forest()) as attached ggplot2 for each row.
  • Removed g_forest() and its dependencies.

Provide more detail here as needed.
#160

# Simple example ------------------------------------------------------------
trial |>
  select(age, marker, grade, response) |>
  tbl_uvregression(
    y = response,
    method = glm,
    method.args = list(family = binomial),
    exponentiate = TRUE,
    hide_n = TRUE
  ) |>
  modify_column_merge(
    pattern = "{estimate} (95% CI {ci}; {p.value})",
    rows = !is.na(estimate)
  ) |>
  modify_header(estimate = "**Odds Ratio**") |>
  add_forest(table_engine = "gt")

# Realistic example ---------------------------------------------------------
trial |>
  tbl_roche_subgroups(
    rsp = "response",
    by = "trt",
    subgroups = c("grade", "stage"),
    ~ glm(response ~ trt, data = .x) |>
      gtsummary::tbl_regression(
        show_single_row = trt,
        exponentiate = TRUE
      )
  ) |>
  add_forest(pvalue = starts_with("p.value"), table_engine = "flextable")

New generic format (inspired by gtforester @ddsjoberg)
image

More specific output:
image


Pre-review Checklist (if item does not apply, mark is as complete)

  • All GitHub Action workflows pass with a ✅
  • PR branch has pulled the most recent updates from master branch: usethis::pr_merge_main()
  • If a bug was fixed, a unit test was added.
  • Code coverage is suitable for any new functions/features (generally, 100% coverage for new code): devtools::test_coverage()
  • Request a reviewer

Reviewer Checklist (if item does not apply, mark is as complete)

  • If a bug was fixed, a unit test was added.
  • Run pkgdown::build_site(). Check the R console for errors, and review the rendered website.
  • Code coverage is suitable for any new functions/features: devtools::test_coverage()

When the branch is ready to be merged:

  • Update NEWS.md with the changes from this pull request under the heading "# cards (development version)". If there is an issue associated with the pull request, reference it in parentheses at the end update (see NEWS.md for examples).
  • All GitHub Action workflows pass with a ✅
  • Approve Pull Request
  • Merge the PR. Please use "Squash and merge" or "Rebase and merge".

Comment thread R/add_forest.R
Copy link
Copy Markdown
Contributor Author

@Melkiades Melkiades left a comment

Choose a reason for hiding this comment

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

@shajoezhu @BFalquet let me know what you think! I managed to get also the flextable output to work with our theme

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 4, 2026

Unit Tests Summary

  1 files   77 suites   1m 52s ⏱️
 77 tests  77 ✅ 0 💤 0 ❌
197 runs  197 ✅ 0 💤 0 ❌

Results for commit f018e93.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 4, 2026

Unit Test Performance Difference

Test Suite $Status$ Time on main $±Time$ $±Tests$ $±Skipped$ $±Failures$ $±Errors$
add_forest 👶 $+0.00$ $+5$ $0$ $0$ $0$
forestplot 💀 $0.04$ $-0.04$ $-1$ $-1$ $0$ $0$
tbl_roche_subgroups 👶 $+0.00$ $+2$ $0$ $0$ $0$
Additional test case details
Test Suite $Status$ Time on main $±Time$ Test Case
add_forest 👶 $+0.01$ add_forest_handles_extreme_limits_and_character_NA_p_values_safely
add_forest 👶 $+13.76$ add_forest_table_engine_flextable_works
add_hierarchical_count_row 💔 $1.17$ $+2.68$ add_hierarchical_count_row_works
forestplot 💀 $0.04$ $-0.04$ test_g_forest_works
gg_km 💔 $0.21$ $+1.58$ gg_km_works_with_default_inputs
tbl_baseline_chg 💚 $13.85$ $-12.47$ tbl_baseline_chg_works
tbl_hierarchical_rate_by_grade 💔 $1.09$ $+3.62$ tbl_hierarchical_rate_by_grade_works
tbl_roche_subgroups 👶 $+23.10$ tbl_roche_subgroups_time_to_event_NULL_works
tbl_roche_subgroups 👶 $+0.00$ tbl_roche_subgroups_time_to_event_works
tbl_survfit_quantiles 💚 $5.44$ $-4.98$ tbl_survfit_quantiles_works
theme_gtsummary_roche 💚 $5.17$ $-3.32$ theme_gtsummary_roche_works

Results for commit b21b008

♻️ This comment has been updated with latest results.

Copy link
Copy Markdown
Contributor

@BFalquet BFalquet left a comment

Choose a reason for hiding this comment

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

Nice work but apparently the version of tidyselect was updated and using an external vector in selections was deprecated. => use NSE or all_of (there are couple of occurences). Also we get a warning in the .determine_ggplot_header and ..plot_centered_axis as well as in couple of other unmodified function because we dont use .data. add them to utils::globalVariables or use .data/.env

Comment thread R/add_forest.R
Comment thread R/add_forest_utils.R
Comment thread R/add_forest.R
@Melkiades
Copy link
Copy Markdown
Contributor Author

Nice work but apparently the version of tidyselect was updated and using an external vector in selections was deprecated. => use NSE or all_of (there are couple of occurences). Also we get a warning in the .determine_ggplot_header and ..plot_centered_axis as well as in couple of other unmodified function because we dont use .data. add them to utils::globalVariables or use .data/.env

Yes I saw the first issue but if you follow it, it seems to be related to process_selectors which is a cards function... I will investigate the second issue!

Comment thread R/add_forest.R
Signed-off-by: Davide Garolini <dgarolini@gmail.com>
Comment thread R/add_forest.R
Comment thread R/add_forest_utils.R
@Melkiades
Copy link
Copy Markdown
Contributor Author

@BFalquet @shajoezhu I think now this is complete! I added some edge cases ;)

@shajoezhu
Copy link
Copy Markdown
Contributor

hi @Melkiades , tests still failing. can you take a look please.

@shajoezhu
Copy link
Copy Markdown
Contributor

hi @walkowif , I was wondering do you know why the CLA is failing? Thanks

@walkowif
Copy link
Copy Markdown
Contributor

@shajoezhu Even though in the check summary it appears as if CLA was failing, it's not.

image

The failing check is Unit Tests Summary and CLA is in fact passing - they are only grouped together under pull_request_target CI/CD event.

image

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 25, 2026

badge

Code Coverage Summary

Filename                               Stmts    Miss  Cover    Missing
-----------------------------------  -------  ------  -------  ------------------------------------------------------------------------------------------------
R/add_blank_rows.R                        63       0  100.00%
R/add_difference_row.R                   101       0  100.00%
R/add_forest_utils.R                      97      10  89.69%   76-79, 94-100
R/add_forest.R                           137       0  100.00%
R/add_hierarchical_count_row.R            33       0  100.00%
R/annotate_gg_km.R                       145       9  93.79%   86-89, 108-112
R/crane-package.R                          2       2  0.00%    25-26
R/deprecated.R                             6       6  0.00%    15-21
R/get_cox_pairwise_df.R                   50      13  74.00%   68-71, 74-77, 82, 92-95
R/gg_km_utils.R                          102      16  84.31%   94, 134-151, 167
R/gg_km.R                                143      37  74.13%   54-57, 74, 101, 175-180, 183-186, 196-198, 203-204, 238-240, 247-250, 254, 265-269, 282, 284-286
R/label_roche.R                           72       0  100.00%
R/modify_header_rm_md.R                   18       2  88.89%   35-36
R/modify_zero_recode.R                    13       0  100.00%
R/tbl_baseline_chg.R                     186       0  100.00%
R/tbl_hierarchical_rate_and_count.R      148       0  100.00%
R/tbl_hierarchical_rate_by_grade.R       271       3  98.89%   162-164
R/tbl_listing.R                           35       0  100.00%
R/tbl_null_report.R                        9       0  100.00%
R/tbl_roche_subgroups.R                  128       0  100.00%
R/tbl_roche_summary.R                     64       0  100.00%
R/tbl_shift.R                            116       0  100.00%
R/tbl_survfit_quantiles.R                132       1  99.24%   295
R/tbl_survfit_times.R                     92       0  100.00%
R/theme_gtsummary_roche.R                 78       0  100.00%
R/utils.R                                 36       0  100.00%
TOTAL                                   2277      99  95.65%

Diff against main

Filename                   Stmts    Miss  Cover
-----------------------  -------  ------  --------
R/add_forest_utils.R         +97     +10  +89.69%
R/add_forest.R              +137       0  +100.00%
R/tbl_roche_subgroups.R       +9    -119  +100.00%
TOTAL                       +243    -109  +9.32%

Results for commit: f018e93

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

@Melkiades
Copy link
Copy Markdown
Contributor Author

Hi @walkowif, I think w/o {broom.helpers} tbl_regression does not work well. Could we add it to macos systems? I will add a skip if not installed meanwhile.

Error in loadNamespace(x): there is no package called 'broom.helpers'

@walkowif
Copy link
Copy Markdown
Contributor

@Melkiades Most likely this is because broom.helpers was removed from DESCRIPTION in this PR.

image

It's missing from .github/pkg.lock in this PR:

image

I compared that with .github/pkg.lock in R CMD check workflow in #166:

image

@shajoezhu
Copy link
Copy Markdown
Contributor

let's add it into suggest, i think it will be fine

@shajoezhu
Copy link
Copy Markdown
Contributor

@Melkiades one last error in the check

Melkiades and others added 2 commits February 26, 2026 22:29
Signed-off-by: Joe Zhu <sha.joe.zhu@gmail.com>
Copy link
Copy Markdown
Contributor

@shajoezhu shajoezhu left a comment

Choose a reason for hiding this comment

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

hey guys, this looks good to me now. I am going to merge this in and unblock the downstream, we can refactor this if needs.

Comment thread DESCRIPTION
Comment thread R/add_forest.R
@shajoezhu shajoezhu merged commit f3bfd9b into main Feb 27, 2026
34 checks passed
@shajoezhu shajoezhu deleted the 160_gt_forest_rework@main branch February 27, 2026 04:51
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants