Skip to content

Extend annotate_lineplot_df(): mean_se, custom labels, blank timepoints - #317

Open
Melkiades wants to merge 3 commits into
mainfrom
307_annotate_mean_se
Open

Extend annotate_lineplot_df(): mean_se, custom labels, blank timepoints#317
Melkiades wants to merge 3 commits into
mainfrom
307_annotate_mean_se

Conversation

@Melkiades

@Melkiades Melkiades commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

What changes are proposed in this pull request?

  • annotate_lineplot_df() gains a "mean_se" summary_stats option reporting the mean +/- 1 standard error interval, matching the error bars drawn by gg_lineplot(variability = "se"). Its row label defaults to "Mean -/+ 1xSE" and is configurable via the new se_label argument. (Add SE to annotate_lineplot_df() summary table #307)
  • annotate_lineplot_df() gains a labels argument to rename statistic rows (e.g. labels = c(mean = "LS mean") for an MMRM plot) and a blank_timepoints argument to blank the continuous statistics at fixed timepoints while keeping n (e.g. a constant change-from-baseline visit where the mean/SD/CI are 0 by construction). (Add SE to annotate_lineplot_df() summary table #307)

These are follow-ups from annotating MMRM change-from-baseline plots:

  • "mean_se" mirrors the plot's SE error bars in the table (bounds delegate to the same .calc_stats() helper the plot uses, so they can never disagree).
  • labels lets an MMRM plot report "LS mean" instead of the generic "Mean".
  • blank_timepoints removes the meaningless 0.00 mean/SD/CI at the constant baseline visit while keeping the sample size.

Reference GitHub issue associated with pull request. e.g., 'closes #'

Part of #307.


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".

Report the mean +/- 1 standard error interval in the annotation table,
matching the error bars drawn by gg_lineplot(variability = "se") so the
table and plot always agree. The row label defaults to "Mean -/+ 1xSE"
and is configurable via the new se_label argument.
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Unit Tests Summary

  1 files  314 suites   1m 53s ⏱️
314 tests 314 ✅ 0 💤 0 ❌
909 runs  909 ✅ 0 💤 0 ❌

Results for commit 0fb818a.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Unit Test Performance Difference

Additional test case details
Test Suite $Status$ Time on main $±Time$ Test Case
annotate_gg 👶 $+0.00$ annotate_lineplot_df_blanks_continuous_stats_at_blank_timepoints
annotate_gg 👶 $+0.00$ annotate_lineplot_df_mean_se_label_is_configurable_via_labels
annotate_gg 👶 $+0.00$ annotate_lineplot_df_mean_se_reports_the_mean_1_SE_interval
annotate_gg 👶 $+0.00$ annotate_lineplot_df_rejects_invalid_labels
annotate_gg 👶 $+0.00$ annotate_lineplot_df_renames_statistics_via_labels
annotate_gg 👶 $+0.00$ annotate_lineplot_df_warns_on_unknown_blank_timepoints
annotate_gg_km 💔 $1.76$ $+1.52$ annotate_riskdf_handles_all_branches_and_inputs
tbl_baseline_chg 💚 $12.75$ $-1.43$ tbl_baseline_chg_works
tbl_hierarchical_rate_by_grade 💚 $11.81$ $-2.33$ tbl_hierarchical_rate_by_grade_works
tbl_mmrm 💔 $2.12$ $+1.18$ se_calculates_standard_error_correctly
tbl_rmpt 💚 $5.89$ $-1.64$ tbl_rmpt_works_with_default_parameters_Example_1_
tbl_roche_subgroups 💔 $5.74$ $+1.30$ tbl_roche_subgroups_time_to_event_NULL_works
tbl_shift 💚 $3.99$ $-1.47$ tbl_shift_strata_location_
tbl_survfit_quantiles 💔 $0.62$ $+1.20$ tbl_survfit_quantiles_works
tbl_survfit_times 💚 $1.79$ $-1.49$ tbl_survfit_times_works

Results for commit 84c8aa9

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

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                             139       0  100.00%
R/add_hierarchical_count_row.R              33       0  100.00%
R/adjust_stat_columns_wrap.R                29       1  96.55%   59
R/annotate_gg_km.R                         141       0  100.00%
R/annotate_gg_pkc.R                        100       0  100.00%
R/annotate_gg.R                            123       0  100.00%
R/ard_tabulate_abnormal_by_baseline.R       65       0  100.00%
R/crane-package.R                            2       2  0.00%    26-27
R/deprecated.R                              21      21  0.00%    18-54
R/df_add_poolings.R                         41       0  100.00%
R/get_cox_pairwise_df.R                    163       0  100.00%
R/gg_km_utils.R                             39      14  64.10%   20-37
R/gg_km.R                                  143      37  74.13%   55-58, 75, 102, 176-181, 184-187, 197-199, 204-205, 239-241, 248-251, 255, 266-270, 283, 285-287
R/gg_lineplot.R                            121       0  100.00%
R/gg_mmrm_lineplot.R                       102       1  99.02%   106
R/gg_pkc_lineplot.R                         98       0  100.00%
R/gg_utils.R                               222       0  100.00%
R/label_roche.R                             72       0  100.00%
R/modify_header_rm_md.R                     18       2  88.89%   35-36
R/modify_split_caption.R                    26       0  100.00%
R/modify_zero_recode.R                      20       1  95.00%   64
R/pk_helper.R                              499       0  100.00%
R/reverse_difference_ci.R                   33       0  100.00%
R/tbl_baseline_chg.R                       188       0  100.00%
R/tbl_coxph.R                               90       1  98.89%   229
R/tbl_hierarchical_incidence_rate.R        291       4  98.63%   430-433
R/tbl_hierarchical_rate_and_count.R        339      13  96.17%   343, 425, 446-456
R/tbl_hierarchical_rate_by_grade.R         317       3  99.05%   169-171
R/tbl_listing.R                             36       0  100.00%
R/tbl_mmrm.R                               344       6  98.26%   452-456, 548
R/tbl_null_report.R                         10       0  100.00%
R/tbl_rmpt.R                               157      12  92.36%   299-304, 316-321
R/tbl_roche_subgroups.R                    157       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                  154       0  100.00%
R/tbl_survfit_times.R                       92       0  100.00%
R/tbl_with_pools.R                          79       1  98.73%   317
R/theme_gtsummary_roche.R                   87       1  98.85%   61
R/utils.R                                   42       0  100.00%
TOTAL                                     5074     130  97.44%

Diff against main

Filename           Stmts    Miss  Cover
---------------  -------  ------  --------
R/annotate_gg.R      +29       0  +100.00%
TOTAL                +29       0  +0.01%

Results for commit: 0fb818a

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

Add a labels argument to override statistic row labels (e.g.
labels = c(mean = "LS mean") for an MMRM plot) and a blank_timepoints
argument to blank the continuous statistics at fixed timepoints while
keeping n, for a constant change-from-baseline visit where the
mean/SD/CI are 0 by construction.
@Melkiades Melkiades changed the title Add "mean_se" option to annotate_lineplot_df() Extend annotate_lineplot_df(): mean_se, custom labels, blank timepoints Sep 3, 2026
The general labels argument already relabels any statistic, so the
special-case se_label was redundant. The mean_se row keeps its default
"Mean -/+ 1xSE" label and is now relabelled the same way as every other
statistic, e.g. labels = c(mean_se = "Mean +/- SE").
Comment thread R/annotate_gg.R
Comment on lines +240 to +257
# Blank the continuous statistics at fixed timepoints (e.g. a constant-zero
# change-from-baseline visit in an MMRM plot), where a "0.00" mean/SD/CI is an
# artifact of the constant rather than a real estimate. The count ("n") is a
# genuine value and is kept.
if (!is.null(blank_timepoints)) {
missing_tp <- setdiff(blank_timepoints, names(formatted_df))
if (length(missing_tp) > 0) {
cli::cli_warn(c(
"!" = "Timepoint{?s} in {.arg blank_timepoints} not found: {.val {missing_tp}}.",
"i" = "Available timepoint columns are {.val {setdiff(names(formatted_df), c(names(formatted_df)[1], 'Group'))}}."
))
}
n_label <- trimws(stat_labels[["n"]])
blank_rows <- is_stat & trimws(raw_labels) != n_label
for (tp in intersect(blank_timepoints, names(formatted_df))) {
formatted_df[blank_rows, tp] <- ""
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

should we give the option to add 0 instead? or whatever NA label?

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.

1 participant