Skip to content

Commit b6c2f28

Browse files
authored
Add font_size to annotate_lineplot_df() (#296)
**What changes are proposed in this pull request?** * `annotate_lineplot_df()` gains a `font_size` argument to control the summary table font size, and `annotate_pkc_df()` now applies its `text_size` argument. (#295) `annotate_lineplot_df()` had no way to set the summary table font size, so it was fixed at the `df2gg_aligned()` defaults. `font_size` maps to `text_size`/`label_size`, matching `annotate_riskdf()`. `annotate_pkc_df()` already declared `text_size` but never forwarded it. **Reference GitHub issue associated with pull request.** closes #295 -------------------------------------------------------------------------------- Pre-review Checklist (if item does not apply, mark is as complete) - [x] **All** GitHub Action workflows pass with a ✅ - [x] PR branch has pulled the most recent updates from master branch: `usethis::pr_merge_main()` - [x] If a bug was fixed, a unit test was added. - [x] Code coverage is suitable for any new functions/features (generally, 100% coverage for new code): `devtools::test_coverage()` - [ ] Request a reviewer --------- Signed-off-by: Davide Garolini <dgarolini@gmail.com>
1 parent cd6a981 commit b6c2f28

7 files changed

Lines changed: 117 additions & 6 deletions

File tree

‎NEWS.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
* Added `modify_split_caption()` to subtitle each page of a split `{gtsummary}` table (e.g. from `tbl_listing()`, `tbl_baseline_chg()`, or `tbl_shift()`) from its split level via a glue `pattern` (default `"Parameter: {spl_level}"`) and hide the now-redundant split column. (#282)
44

5+
* `annotate_lineplot_df()` and `annotate_pkc_df()` gain a `font_size` argument to control the summary table font size, matching `annotate_riskdf()`. The `text_size` argument of `annotate_pkc_df()` is soft-deprecated in favor of `font_size`. (#295)
6+
57
* Renamed `imputation_rules()` to `pk_imputation_rules()` to make its PK scope explicit. It applies BLQ display rules to PK summary statistics based on the BLQ ratio and dosing timing, and now marks any missing statistic (e.g. standard deviation or CV% when `n = 1`) as `"NE"` (not estimable). (#293)
68

79
* Renamed `d_pkparam()` to `pk_param_metadata()` and `h_pkparam_sort()` to `pk_param_sort()`, dropping the `d_`/`h_` prefixes. `pk_param_sort()` now warns about parameter codes missing from the reference and keeps their rows instead of dropping them silently. (#293)

‎R/annotate_gg.R‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#' Can be a single integer (e.g., `2`), a vector of integers matching the statistics
2020
#' (e.g., `c(0, 2, 2)`), or a `gtsummary` style formula. Defaults to `NULL`
2121
#' (uses `gtsummary` default auto-formatting).
22+
#' @param font_size (`numeric`)\cr
23+
#' Base font size for the summary table text. Defaults to `10`.
2224
#' @param rel_height_plot (`numeric`)\cr
2325
#' Relative height of the plot vs the table. Defaults to `0.75`.
2426
#'
@@ -62,6 +64,7 @@ annotate_lineplot_df <- function(gg_plt,
6264
group = NULL,
6365
summary_stats = c("n", "mean", "sd"),
6466
digits = NULL,
67+
font_size = 10,
6568
rel_height_plot = 0.75) {
6669
if (!inherits(gg_plt, "crane_gg_line")) {
6770
cli::cli_warn(c(
@@ -164,6 +167,8 @@ annotate_lineplot_df <- function(gg_plt,
164167
show_xaxis = FALSE,
165168
type = "GEN",
166169
y_labels = y_labels,
170+
text_size = font_size / ggplot2::.pt,
171+
label_size = font_size,
167172
rel_height_plot = rel_height_plot
168173
)
169174
}

‎R/annotate_gg_pkc.R‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
#' Can be a single integer (e.g., `2`), a vector of integers matching the statistics
2020
#' (e.g., `c(0, 2, 2)`), or a `gtsummary` style formula. Defaults to `NULL`
2121
#' (uses `gtsummary` default auto-formatting).
22-
#' @param text_size (`numeric`)\cr
23-
#' The font size for the table text. Defaults to `3.5`.
22+
#' @param font_size (`numeric`)\cr
23+
#' Base font size for the summary table text. Defaults to `10`.
24+
#' @param text_size `r lifecycle::badge("deprecated")`\cr
25+
#' Use `font_size` instead.
2426
#' @param rel_height_plot (`numeric`)\cr
2527
#' Relative height of the plot vs the table. Defaults to `0.75`.
2628
#' @returns A ggplot2 object: a plot with a table at the bottom.
@@ -61,6 +63,13 @@
6163
#' summary_stats = c("n", "median", "iqr"),
6264
#' digits = c(0, 2, 2)
6365
#' )
66+
#'
67+
#' # Annotate with a larger summary table font
68+
#' annotate_pkc_df(
69+
#' data = df_pk,
70+
#' gg_plt = p_pk,
71+
#' font_size = 12
72+
#' )
6473
#' @export
6574
annotate_pkc_df <- function(gg_plt,
6675
data,
@@ -69,8 +78,18 @@ annotate_pkc_df <- function(gg_plt,
6978
group = NULL,
7079
summary_stats = c("n", "mean", "sd"),
7180
digits = NULL,
72-
text_size = 3.5,
81+
font_size = 10,
82+
text_size = lifecycle::deprecated(),
7383
rel_height_plot = 0.75) {
84+
if (lifecycle::is_present(text_size)) {
85+
lifecycle::deprecate_soft(
86+
"0.3.4",
87+
"crane::annotate_pkc_df(text_size)",
88+
"crane::annotate_pkc_df(font_size)"
89+
)
90+
font_size <- text_size * ggplot2::.pt
91+
}
92+
7493
# 1. Input Validation---------------------------------------------------------
7594
if (!inherits(gg_plt, "crane_gg_pkc")) {
7695
cli::cli_warn(c(
@@ -181,6 +200,7 @@ annotate_pkc_df <- function(gg_plt,
181200
show_xaxis = FALSE,
182201
type = "PK",
183202
y_labels = pk_y_labels,
203+
text_size = font_size / ggplot2::.pt,
184204
rel_height_plot = rel_height_plot
185205
)
186206

‎man/annotate_lineplot_df.Rd‎

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎man/annotate_pkc_df.Rd‎

Lines changed: 14 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/testthat/test-annotate_gg.R‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,21 @@ test_that("annotate_lineplot_df formats numeric digits correctly", {
135135
# Check 'sd' has a decimal point followed by EXACTLY 2 digits (e.g., "0.71")
136136
expect_true(grepl("\\.[0-9]{2}$", val_sd))
137137
})
138+
139+
test_that("annotate_lineplot_df forwards font_size to df2gg_aligned", {
140+
captured <- NULL
141+
mock_df2gg <- function(df, ..., text_size, label_size) {
142+
captured <<- list(text_size = text_size, label_size = label_size)
143+
df
144+
}
145+
146+
testthat::with_mocked_bindings(
147+
{
148+
annotate_lineplot_df(gg_plt = p_valid, data = mock_adlb, font_size = 14)
149+
},
150+
df2gg_aligned = mock_df2gg
151+
)
152+
153+
expect_equal(captured$label_size, 14)
154+
expect_equal(captured$text_size, 14 / ggplot2::.pt)
155+
})

‎tests/testthat/test-annotate_gg_pkc.R‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,54 @@ test_that("annotate_pkc_df formats numeric digits correctly", {
201201
# Check 'sd' has a decimal point followed by EXACTLY 2 digits (e.g., "12.34")
202202
expect_true(grepl("\\.[0-9]{2}$", val_sd))
203203
})
204+
205+
test_that("annotate_pkc_df forwards font_size to df2gg_aligned", {
206+
df_pk <- data.frame(
207+
time = rep(c(0, 1, 2), each = 4),
208+
conc = runif(12, 10, 100),
209+
arm = rep(c("Cohort A", "Cohort B"), times = 6)
210+
)
211+
p <- gg_pkc_lineplot(
212+
data = df_pk, time_var = time, analyte_var = conc, group = arm, log_y = FALSE
213+
)
214+
215+
captured <- NULL
216+
mock_df2gg <- function(df, ..., text_size) {
217+
captured <<- text_size
218+
df
219+
}
220+
221+
testthat::with_mocked_bindings(
222+
annotate_pkc_df(gg_plt = p, data = df_pk, font_size = 14),
223+
df2gg_aligned = mock_df2gg
224+
)
225+
226+
expect_equal(captured, 14 / ggplot2::.pt)
227+
})
228+
229+
test_that("annotate_pkc_df soft-deprecates text_size but keeps behaviour", {
230+
df_pk <- data.frame(
231+
time = rep(c(0, 1, 2), each = 4),
232+
conc = runif(12, 10, 100),
233+
arm = rep(c("Cohort A", "Cohort B"), times = 6)
234+
)
235+
p <- gg_pkc_lineplot(
236+
data = df_pk, time_var = time, analyte_var = conc, group = arm, log_y = FALSE
237+
)
238+
239+
captured <- NULL
240+
mock_df2gg <- function(df, ..., text_size) {
241+
captured <<- text_size
242+
df
243+
}
244+
245+
# text_size is passed through unchanged (round-trips via font_size)
246+
lifecycle::expect_deprecated(
247+
testthat::with_mocked_bindings(
248+
annotate_pkc_df(gg_plt = p, data = df_pk, text_size = 5),
249+
df2gg_aligned = mock_df2gg
250+
)
251+
)
252+
253+
expect_equal(captured, 5)
254+
})

0 commit comments

Comments
 (0)