Skip to content

Commit c7c78ee

Browse files
committed
Fix median annotation and update vignette
1 parent ca26a58 commit c7c78ee

4 files changed

Lines changed: 19 additions & 11 deletions

File tree

R/baseline_table.R

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,21 @@ create_baseline_table <- function(data,
435435
title = "Baseline Characteristics by Treatment Arm"
436436
)
437437

438-
gt_table <- gt::fmt_missing(
439-
gt_table,
440-
columns = gt::everything(),
441-
missing_text = ""
442-
)
438+
# Check gt version and use appropriate function
439+
# sub_missing was introduced in gt v0.6.0 to replace fmt_missing
440+
if (utils::packageVersion("gt") >= "0.6.0") {
441+
gt_table <- gt::sub_missing(
442+
gt_table,
443+
columns = gt::everything(),
444+
missing_text = ""
445+
)
446+
} else {
447+
gt_table <- gt::fmt_missing(
448+
gt_table,
449+
columns = gt::everything(),
450+
missing_text = ""
451+
)
452+
}
443453

444454
gt_table <- gt::tab_style(
445455
gt_table,

R/kmplotting_helpers.R

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,12 @@ add_risk_table <- function(risk.points, rpoints0, rpoints1, col.0, col.1, risk.c
152152
#' @param med.digits Integer; number of digits to display for median and confidence interval.
153153
#' @param med.cex Numeric; text size for median annotation.
154154
#' @param med.font Integer; font for median annotation.
155-
#' @param xmed.fraction Numeric; fraction of the x-axis for annotation placement (e.g., 0.8 for 80\% to the right).
155+
#' @param xmed.fraction Numeric; fraction of the x-axis for annotation placement (e.g., 0.8 for 80\\% to the right).
156156
#' @param ymed.offset Numeric; offset from the top of the plot for annotation placement.
157157
#'
158158
#' @importFrom graphics text
159159
#' @return Invisibly returns NULL. Used for plotting side effects.
160160
#' @export
161-
162161
add_median_annotation <- function(medians_df, med.digits, med.cex, med.font, xmed.fraction, ymed.offset) {
163162
medians_df$label <- paste0(
164163
format(medians_df$quantile, digits = med.digits), " [",
@@ -169,14 +168,13 @@ add_median_annotation <- function(medians_df, med.digits, med.cex, med.font, xme
169168
paste(medians_df$group, medians_df$label, sep = ": "),
170169
collapse = "\n"
171170
)
172-
173171
usr <- par("usr")
174172
x_pos <- usr[2] * xmed.fraction
175173
y_pos <- usr[4] - ymed.offset
176-
177174
text(x = x_pos, y = y_pos, labels = annotation_text, adj = c(0, 1), cex = med.cex, font = med.font)
178175
}
179176

177+
180178
#' Add legends to KM plot
181179
#'
182180
#' Adds legends for Cox model, log-rank test, and arms to a Kaplan-Meier plot.

man/add_median_annotation.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/weightedsurv_examples.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ baseline_table <- create_baseline_table(
461461
data = df_CTC,
462462
treat_var = "treat",
463463
vars_continuous = c("age", "pgr", "er", "nodes"),
464-
vars_categorical = c("size","meno","chemo","er_negative"),
464+
vars_categorical = c("size","meno","er_negative"),
465465
show_pvalue = TRUE,
466466
show_smd = TRUE
467467
)

0 commit comments

Comments
 (0)