From 6fdc7579be8448cd7bf078c29bbaad7781081598 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 12 Nov 2024 07:53:54 +0000 Subject: [PATCH] [skip roxygen] [skip vbump] Roxygen Man Pages Auto Update --- DESCRIPTION | 3 - man/analyze_variables.Rd | 32 ++++- man/g_km.Rd | 262 ++++++++++-------------------------- man/h_data_plot.Rd | 42 +----- man/h_decompose_gg.Rd | 47 +------ man/h_g_ipp.Rd | 45 +------ man/h_ggkm.Rd | 89 ++++-------- man/h_grob_coxph.Rd | 50 ++----- man/h_grob_median_surv.Rd | 42 +----- man/h_grob_tbl_at_risk.Rd | 72 +--------- man/h_grob_y_annot.Rd | 36 +---- man/h_km_layout.Rd | 55 ++------ man/h_tbl_coxph_pairwise.Rd | 48 +++---- man/h_tbl_median_surv.Rd | 24 +--- man/h_xticks.Rd | 37 +---- man/try_car_anova.Rd | 4 +- 16 files changed, 188 insertions(+), 700 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 466418b93a..8d8b2bbe06 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -144,8 +144,6 @@ Collate: 'h_survival_duration_subgroups.R' 'imputation_rule.R' 'incidence_rate.R' - 'individual_patient_plot.R' - 'kaplan_meier_plot.R' 'logistic_regression.R' 'missing_data.R' 'odds_ratio.R' @@ -168,7 +166,6 @@ Collate: 'summarize_glm_count.R' 'summarize_num_patients.R' 'summarize_patients_exposure_in_cols.R' - 'summarize_variables.R' 'survival_biomarkers_subgroups.R' 'survival_coxph_pairwise.R' 'survival_duration_subgroups.R' diff --git a/man/analyze_variables.Rd b/man/analyze_variables.Rd index 7c38e531ec..18a6b603dc 100644 --- a/man/analyze_variables.Rd +++ b/man/analyze_variables.Rd @@ -37,14 +37,14 @@ s_summary(x, na.rm = TRUE, denom, .N_row, .N_col, .var, ...) .N_row, .N_col, .var, - control = control_summarize_vars(), + control = control_analyze_vars(), ... ) \method{s_summary}{factor}( x, na.rm = TRUE, - denom = c("n", "N_row", "N_col"), + denom = c("n", "N_col", "N_row"), .N_row, .N_col, ... @@ -53,7 +53,7 @@ s_summary(x, na.rm = TRUE, denom, .N_row, .N_col, .var, ...) \method{s_summary}{character}( x, na.rm = TRUE, - denom = c("n", "N_row", "N_col"), + denom = c("n", "N_col", "N_row"), .N_row, .N_col, .var, @@ -64,13 +64,29 @@ s_summary(x, na.rm = TRUE, denom, .N_row, .N_col, .var, ...) \method{s_summary}{logical}( x, na.rm = TRUE, - denom = c("n", "N_row", "N_col"), + denom = c("n", "N_col", "N_row"), .N_row, .N_col, ... ) -a_summary(x, ..., .N_row, .N_col, .var) +a_summary( + x, + .N_col, + .N_row, + .var = NULL, + .df_row = NULL, + .ref_group = NULL, + .in_ref_col = FALSE, + compare = FALSE, + .stats = NULL, + .formats = NULL, + .labels = NULL, + .indent_mods = NULL, + na.rm = TRUE, + na_str = default_na_str(), + ... +) } \arguments{ \item{lyt}{(\code{PreDataTableLayouts})\cr layout that analyses will be added to.} @@ -143,6 +159,12 @@ See more about \code{type} in \code{\link[stats:quantile]{stats::quantile()}}. \item{verbose}{(\code{flag})\cr defaults to \code{TRUE}, which prints out warnings and messages. It is mainly used to print out information about factor casting.} +\item{.df_row}{(\code{data.frame})\cr data frame across all of the columns for the given row split.} + +\item{.ref_group}{(\code{data.frame} or \code{vector})\cr the data corresponding to the reference group.} + +\item{.in_ref_col}{(\code{flag})\cr \code{TRUE} when working with the reference level, \code{FALSE} otherwise.} + \item{compare}{(\code{flag})\cr whether comparison statistics should be analyzed instead of summary statistics (\code{compare = TRUE} adds \code{pval} statistic comparing against reference group).} } diff --git a/man/g_km.Rd b/man/g_km.Rd index 4191e04b4a..c46349a96c 100644 --- a/man/g_km.Rd +++ b/man/g_km.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/g_km.R, R/kaplan_meier_plot.R +% Please edit documentation in R/g_km.R \name{g_km} \alias{g_km} \alias{kaplan_meier} @@ -20,59 +20,34 @@ g_km( xlab = "Days", yval = c("Survival", "Failure"), ylab = paste(yval, "Probability"), + ylim = NULL, title = NULL, footnotes = NULL, - draw = TRUE, - newpage = TRUE, - gp = NULL, - vp = NULL, - name = NULL, - font_size = 12, + font_size = 10, ci_ribbon = FALSE, - ggtheme = nestcolor::theme_nest(), annot_at_risk = TRUE, + annot_at_risk_title = TRUE, annot_surv_med = TRUE, annot_coxph = FALSE, annot_stats = NULL, annot_stats_vlines = FALSE, control_coxph_pw = control_coxph(), - position_coxph = c(0, 0.05), - position_surv_med = c(0.9, 0.9) -) - -g_km( - df, - variables, - control_surv = control_surv_timepoint(), - col = NULL, - lty = NULL, - lwd = 0.5, - censor_show = TRUE, - pch = 3, - size = 2, - max_time = NULL, - xticks = NULL, - xlab = "Days", - yval = c("Survival", "Failure"), - ylab = paste(yval, "Probability"), - title = NULL, - footnotes = NULL, - draw = TRUE, - newpage = TRUE, - gp = NULL, - vp = NULL, - name = NULL, - font_size = 12, - ci_ribbon = FALSE, - ggtheme = nestcolor::theme_nest(), - annot_at_risk = TRUE, - annot_surv_med = TRUE, - annot_coxph = FALSE, - annot_stats = NULL, - annot_stats_vlines = FALSE, - control_coxph_pw = control_coxph(), - position_coxph = c(0, 0.05), - position_surv_med = c(0.9, 0.9) + ref_group_coxph = NULL, + control_annot_surv_med = control_surv_med_annot(), + control_annot_coxph = control_coxph_annot(), + legend_pos = NULL, + rel_height_plot = 0.75, + ggtheme = NULL, + as_list = FALSE, + draw = lifecycle::deprecated(), + newpage = lifecycle::deprecated(), + gp = lifecycle::deprecated(), + vp = lifecycle::deprecated(), + name = lifecycle::deprecated(), + annot_coxph_ref_lbls = lifecycle::deprecated(), + position_coxph = lifecycle::deprecated(), + position_surv_med = lifecycle::deprecated(), + width_annots = lifecycle::deprecated() ) } \arguments{ @@ -83,97 +58,84 @@ g_km( \item \code{tte} (\code{numeric})\cr variable indicating time-to-event duration values. \item \code{is_event} (\code{logical})\cr event variable. \code{TRUE} if event, \code{FALSE} if time to event is censored. \item \code{arm} (\code{factor})\cr the treatment group variable. -\item \code{strat} (\code{character} or \code{NULL})\cr variable names indicating stratification factors. +\item \code{strata} (\code{character} or \code{NULL})\cr variable names indicating stratification factors. }} \item{control_surv}{(\code{list})\cr parameters for comparison details, specified by using the helper function \code{\link[=control_surv_timepoint]{control_surv_timepoint()}}. Some possible parameter options are: \itemize{ \item \code{conf_level} (\code{proportion})\cr confidence level of the interval for survival rate. -\item \code{conf_type} (\code{string})\cr "plain" (default), "log", "log-log" for confidence interval type, +\item \code{conf_type} (\code{string})\cr \code{"plain"} (default), \code{"log"}, \code{"log-log"} for confidence interval type, see more in \code{\link[survival:survfit]{survival::survfit()}}. Note that the option "none" is no longer supported. }} \item{col}{(\code{character})\cr lines colors. Length of a vector should be equal to number of strata from \code{\link[survival:survfit]{survival::survfit()}}.} -\item{lty}{(\code{numeric})\cr line type. Length of a vector should be equal -to number of strata from \code{\link[survival:survfit]{survival::survfit()}}.} +\item{lty}{(\code{numeric})\cr line type. If a vector is given, its length should be equal to the number of strata from +\code{\link[survival:survfit]{survival::survfit()}}.} -\item{lwd}{(\code{numeric})\cr line width. Length of a vector should be equal -to number of strata from \code{\link[survival:survfit]{survival::survfit()}}.} +\item{lwd}{(\code{numeric})\cr line width. If a vector is given, its length should be equal to the number of strata from +\code{\link[survival:survfit]{survival::survfit()}}.} -\item{censor_show}{(\code{flag})\cr whether to show censored.} +\item{censor_show}{(\code{flag})\cr whether to show censored observations.} -\item{pch}{(\code{numeric}, \code{string})\cr value or character of points symbol to indicate censored cases.} +\item{pch}{(\code{string})\cr name of symbol or character to use as point symbol to indicate censored cases.} -\item{size}{(\code{numeric})\cr size of censored point, a class of \code{unit}.} +\item{size}{(\code{numeric(1)})\cr size of censored point symbols.} -\item{max_time}{(\code{numeric})\cr maximum value to show on X axis. Only data values less than or up to +\item{max_time}{(\code{numeric(1)})\cr maximum value to show on x-axis. Only data values less than or up to this threshold value will be plotted (defaults to \code{NULL}).} -\item{xticks}{(\code{numeric}, \code{number}, or \code{NULL})\cr numeric vector of ticks or single number with spacing -between ticks on the x axis. If \code{NULL} (default), \code{\link[labeling:extended]{labeling::extended()}} is used to determine -an optimal tick position on the x axis.} +\item{xticks}{(\code{numeric} or \code{NULL})\cr numeric vector of tick positions or a single number with spacing +between ticks on the x-axis. If \code{NULL} (default), \code{\link[labeling:extended]{labeling::extended()}} is used to determine +optimal tick positions on the x-axis.} -\item{xlab}{(\code{string})\cr label of x-axis.} +\item{xlab}{(\code{string})\cr x-axis label.} -\item{yval}{(\code{string})\cr value of y-axis. Options are \code{Survival} (default) and \code{Failure} probability.} +\item{yval}{(\code{string})\cr type of plot, to be plotted on the y-axis. Options are \code{Survival} (default) and \code{Failure} +probability.} -\item{ylab}{(\code{string})\cr label of y-axis.} +\item{ylab}{(\code{string})\cr y-axis label.} -\item{title}{(\code{string})\cr title for plot.} +\item{ylim}{(\code{numeric(2)})\cr vector containing lower and upper limits for the y-axis, respectively. +If \code{NULL} (default), the default scale range is used.} -\item{footnotes}{(\code{string})\cr footnotes for plot.} +\item{title}{(\code{string})\cr plot title.} -\item{draw}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} This function no longer generates \code{grob} objects.} - -\item{newpage}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} This function no longer generates \code{grob} objects.} - -\item{gp}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} This function no longer generates \code{grob} objects.} - -\item{vp}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} This function no longer generates \code{grob} objects.} +\item{footnotes}{(\code{string})\cr plot footnotes.} -\item{name}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} This function no longer generates \code{grob} objects.} - -\item{font_size}{(\code{number})\cr font size to be used.} +\item{font_size}{(\code{numeric(1)})\cr font size to use for all text.} -\item{ci_ribbon}{(\code{flag})\cr draw the confidence interval around the Kaplan-Meier curve.} - -\item{ggtheme}{(\code{theme})\cr a graphical theme as provided by \code{ggplot2} to control outlook of the Kaplan-Meier curve.} +\item{ci_ribbon}{(\code{flag})\cr whether the confidence interval should be drawn around the Kaplan-Meier curve.} \item{annot_at_risk}{(\code{flag})\cr compute and add the annotation table reporting the number of patient at risk matching the main grid of the Kaplan-Meier curve.} +\item{annot_at_risk_title}{(\code{flag})\cr whether the "Patients at Risk" title should be added above the \code{annot_at_risk} +table. Has no effect if \code{annot_at_risk} is \code{FALSE}. Defaults to \code{TRUE}.} + \item{annot_surv_med}{(\code{flag})\cr compute and add the annotation table on the Kaplan-Meier curve estimating the median survival time per group.} -\item{annot_coxph}{(\code{flag})\cr add the annotation table from a \code{\link[survival:coxph]{survival::coxph()}} model.} +\item{annot_coxph}{(\code{flag})\cr whether to add the annotation table from a \code{\link[survival:coxph]{survival::coxph()}} model.} -\item{annot_stats}{(\code{string})\cr statistics annotations to add to the plot. Options are +\item{annot_stats}{(\code{string} or \code{NULL})\cr statistics annotations to add to the plot. Options are \code{median} (median survival follow-up time) and \code{min} (minimum survival follow-up time).} \item{annot_stats_vlines}{(\code{flag})\cr add vertical lines corresponding to each of the statistics specified by \code{annot_stats}. If \code{annot_stats} is \code{NULL} no lines will be added.} -\item{control_coxph_pw}{(\code{list})\cr parameters for comparison details, specified by using -the helper function \code{\link[=control_coxph]{control_coxph()}}. Some possible parameter options are: +\item{control_coxph_pw}{(\code{list})\cr parameters for comparison details, specified using the helper function +\code{\link[=control_coxph]{control_coxph()}}. Some possible parameter options are: \itemize{ \item \code{pval_method} (\code{string})\cr p-value method for testing hazard ratio = 1. -Default method is "log-rank", can also be set to "wald" or "likelihood". -\item \code{ties} (\code{string})\cr method for tie handling. Default is "efron", -can also be set to "breslow" or "exact". See more in \code{\link[survival:coxph]{survival::coxph()}} +Default method is \code{"log-rank"}, can also be set to \code{"wald"} or \code{"likelihood"}. +\item \code{ties} (\code{string})\cr method for tie handling. Default is \code{"efron"}, +can also be set to \code{"breslow"} or \code{"exact"}. See more in \code{\link[survival:coxph]{survival::coxph()}} \item \code{conf_level} (\code{proportion})\cr confidence level of the interval for HR. }} -\item{position_coxph}{(\code{numeric})\cr x and y positions for plotting \code{\link[survival:coxph]{survival::coxph()}} model.} - -\item{position_surv_med}{(\code{numeric})\cr x and y positions for plotting annotation table estimating median survival -time per group.} - -\item{annot_at_risk_title}{(\code{flag})\cr whether the "Patients at Risk" title should be added above the \code{annot_at_risk} -table. Has no effect if \code{annot_at_risk} is \code{FALSE}. Defaults to \code{TRUE}.} - \item{ref_group_coxph}{(\code{string} or \code{NULL})\cr level of arm variable to use as reference group in calculations for \code{annot_coxph} table. If \code{NULL} (default), uses the first level of the arm variable.} @@ -193,30 +155,40 @@ the plot, or the middle right of the plot if needed to prevent overlapping.} Relative height of patients at risk table is then \code{1 - rel_height_plot}. If \code{annot_at_risk = FALSE} or \code{as_list = TRUE}, this parameter is ignored.} +\item{ggtheme}{(\code{theme})\cr a graphical theme as provided by \code{ggplot2} to format the Kaplan-Meier plot.} + \item{as_list}{(\code{flag})\cr whether the two \code{ggplot} objects should be returned as a list when \code{annot_at_risk = TRUE}. If \code{TRUE}, a named list with two elements, \code{plot} and \code{table}, will be returned. If \code{FALSE} (default) the patients at risk table is printed below the plot via \code{\link[cowplot:plot_grid]{cowplot::plot_grid()}}.} +\item{draw}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} This function no longer generates \code{grob} objects.} + +\item{newpage}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} This function no longer generates \code{grob} objects.} + +\item{gp}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} This function no longer generates \code{grob} objects.} + +\item{vp}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} This function no longer generates \code{grob} objects.} + +\item{name}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} This function no longer generates \code{grob} objects.} + \item{annot_coxph_ref_lbls}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Please use the \code{ref_lbls} element of \code{control_annot_coxph} instead.} +\item{position_coxph}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Please use the \code{x} and \code{y} elements of +\code{control_annot_coxph} instead.} + +\item{position_surv_med}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Please use the \code{x} and \code{y} elements of +\code{control_annot_surv_med} instead.} + \item{width_annots}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Please use the \code{w} element of \code{control_annot_surv_med} (for \code{surv_med}) and \code{control_annot_coxph} (for \code{coxph})."} } \value{ A \code{ggplot} Kaplan-Meier plot and (optionally) summary table. - -A \code{grob} of class \code{gTree}. } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} -From a survival model, a graphic is rendered along with tabulated annotation -including the number of patient at risk at given time and the median survival -per group. - -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} - From a survival model, a graphic is rendered along with tabulated annotation including the number of patient at risk at given time and the median survival per group. @@ -261,96 +233,4 @@ g_km( control_annot_surv_med = control_surv_med_annot(x = 0.8, y = 0.9, w = 0.35) ) -\dontrun{ -library(dplyr) -library(ggplot2) -library(survival) -library(grid) -library(nestcolor) - -df <- tern_ex_adtte \%>\% - filter(PARAMCD == "OS") \%>\% - mutate(is_event = CNSR == 0) -variables <- list(tte = "AVAL", is_event = "is_event", arm = "ARMCD") - -# 1. Example - basic option - -res <- g_km(df = df, variables = variables) -res <- g_km(df = df, variables = variables, yval = "Failure") -res <- g_km( - df = df, - variables = variables, - control_surv = control_surv_timepoint(conf_level = 0.9), - col = c("grey25", "grey50", "grey75") -) -res <- g_km(df = df, variables = variables, ggtheme = theme_minimal()) -res <- g_km(df = df, variables = variables, ggtheme = theme_minimal(), lty = 1:3) -res <- g_km(df = df, variables = variables, max = 2000) -res <- g_km( - df = df, - variables = variables, - annot_stats = c("min", "median"), - annot_stats_vlines = TRUE -) - -# 2. Example - Arrange several KM curve on a single graph device - -# 2.1 Use case: A general graph on the top, a zoom on the bottom. -grid.newpage() -lyt <- grid.layout(nrow = 2, ncol = 1) \%>\% - viewport(layout = .) \%>\% - pushViewport() - -res <- g_km( - df = df, variables = variables, newpage = FALSE, annot_surv_med = FALSE, - vp = viewport(layout.pos.row = 1, layout.pos.col = 1) -) -res <- g_km( - df = df, variables = variables, max = 1000, newpage = FALSE, annot_surv_med = FALSE, - ggtheme = theme_dark(), - vp = viewport(layout.pos.row = 2, layout.pos.col = 1) -) - -# 2.1 Use case: No annotations on top, annotated graph on bottom -grid.newpage() -lyt <- grid.layout(nrow = 2, ncol = 1) \%>\% - viewport(layout = .) \%>\% - pushViewport() - -res <- g_km( - df = df, variables = variables, newpage = FALSE, - annot_surv_med = FALSE, annot_at_risk = FALSE, - vp = viewport(layout.pos.row = 1, layout.pos.col = 1) -) -res <- g_km( - df = df, variables = variables, max = 2000, newpage = FALSE, annot_surv_med = FALSE, - annot_at_risk = TRUE, - ggtheme = theme_dark(), - vp = viewport(layout.pos.row = 2, layout.pos.col = 1) -) - -# Add annotation from a pairwise coxph analysis -g_km( - df = df, variables = variables, - annot_coxph = TRUE -) - -g_km( - df = df, variables = c(variables, list(strat = "SEX")), - font_size = 15, - annot_coxph = TRUE, - control_coxph = control_coxph(pval_method = "wald", ties = "exact", conf_level = 0.99), - position_coxph = c(0.4, 0.5) -) - -# Change position of the treatment group annotation table. -g_km( - df = df, variables = c(variables, list(strat = "SEX")), - font_size = 15, - annot_coxph = TRUE, - control_coxph = control_coxph(pval_method = "wald", ties = "exact", conf_level = 0.99), - position_surv_med = c(1, 0.7) -) -} - } diff --git a/man/h_data_plot.Rd b/man/h_data_plot.Rd index 7d6e393f01..82b02f5e2c 100644 --- a/man/h_data_plot.Rd +++ b/man/h_data_plot.Rd @@ -1,25 +1,20 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/h_km.R, R/kaplan_meier_plot.R +% Please edit documentation in R/h_km.R \name{h_data_plot} \alias{h_data_plot} \title{Helper function to tidy survival fit data} \usage{ -h_data_plot(fit_km, armval = "All", max_time = NULL) - h_data_plot(fit_km, armval = "All", max_time = NULL) } \arguments{ \item{fit_km}{(\code{survfit})\cr result of \code{\link[survival:survfit]{survival::survfit()}}.} -\item{armval}{(\code{string})\cr used as strata name when treatment arm variable only has one level. Default is "All".} +\item{armval}{(\code{string})\cr used as strata name when treatment arm variable only has one level. Default is \code{"All"}.} -\item{max_time}{(\code{numeric})\cr maximum value to show on X axis. Only data values less than or up to +\item{max_time}{(\code{numeric(1)})\cr maximum value to show on x-axis. Only data values less than or up to this threshold value will be plotted (defaults to \code{NULL}).} } \value{ -A \code{tibble} with columns \code{time}, \code{n.risk}, \code{n.event}, \code{n.censor}, \code{estimate}, \code{std.error}, \code{conf.high}, -\code{conf.low}, \code{strata}, and \code{censor}. - A \code{tibble} with columns \code{time}, \code{n.risk}, \code{n.event}, \code{n.censor}, \code{estimate}, \code{std.error}, \code{conf.high}, \code{conf.low}, \code{strata}, and \code{censor}. } @@ -29,20 +24,6 @@ A \code{tibble} with columns \code{time}, \code{n.risk}, \code{n.event}, \code{n Convert the survival fit data into a data frame designed for plotting within \code{g_km}. -This starts from the \code{\link[broom:reexports]{broom::tidy()}} result, and then: -\itemize{ -\item Post-processes the \code{strata} column into a factor. -\item Extends each stratum by an additional first row with time 0 and probability 1 so that -downstream plot lines start at those coordinates. -\item Adds a \code{censor} column. -\item Filters the rows before \code{max_time}. -} - -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} - -Convert the survival fit data into a data frame designed for plotting -within \code{g_km}. - This starts from the \code{\link[broom:reexports]{broom::tidy()}} result, and then: \itemize{ \item Post-processes the \code{strata} column into a factor. @@ -68,21 +49,4 @@ tern_ex_adtte \%>\% survfit(formula = Surv(AVAL, 1 - CNSR) ~ ARMCD, data = .) \%>\% h_data_plot(armval = "ARM B") -\dontrun{ -library(dplyr) -library(survival) - -# Test with multiple arms -tern_ex_adtte \%>\% - filter(PARAMCD == "OS") \%>\% - survfit(form = Surv(AVAL, 1 - CNSR) ~ ARMCD, data = .) \%>\% - h_data_plot() - -# Test with single arm -tern_ex_adtte \%>\% - filter(PARAMCD == "OS", ARMCD == "ARM B") \%>\% - survfit(form = Surv(AVAL, 1 - CNSR) ~ ARMCD, data = .) \%>\% - h_data_plot(armval = "ARM B") -} - } diff --git a/man/h_decompose_gg.Rd b/man/h_decompose_gg.Rd index 04944dc1f1..db05430261 100644 --- a/man/h_decompose_gg.Rd +++ b/man/h_decompose_gg.Rd @@ -1,27 +1,15 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/h_km.R, R/kaplan_meier_plot.R +% Please edit documentation in R/h_km.R \name{h_decompose_gg} \alias{h_decompose_gg} \title{\code{ggplot} decomposition} \usage{ -h_decompose_gg(gg) - h_decompose_gg(gg) } \arguments{ \item{gg}{(\code{ggplot})\cr a graphic to decompose.} } \value{ -A named \code{list} with elements: -\itemize{ -\item \code{panel}: The panel. -\item \code{yaxis}: The y-axis. -\item \code{xaxis}: The x-axis. -\item \code{xlab}: The x-axis label. -\item \code{ylab}: The y-axis label. -\item \code{guide}: The legend. -} - A named \code{list} with elements: \itemize{ \item \code{panel}: The panel. @@ -35,10 +23,6 @@ A named \code{list} with elements: \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} -The elements composing the \code{ggplot} are extracted and organized in a \code{list}. - -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} - The elements composing the \code{ggplot} are extracted and organized in a \code{list}. } \examples{ @@ -71,33 +55,4 @@ grid.rect(gp = grid::gpar(lty = 1, col = "royalblue", fill = "gray85", lwd = 5)) grid::grid.draw(with(g_el, cbind(ylab, yaxis))) } -\dontrun{ -library(dplyr) -library(survival) -library(grid) - -fit_km <- tern_ex_adtte \%>\% - filter(PARAMCD == "OS") \%>\% - survfit(form = Surv(AVAL, 1 - CNSR) ~ ARMCD, data = .) -data_plot <- h_data_plot(fit_km = fit_km) -xticks <- h_xticks(data = data_plot) -gg <- h_ggkm( - data = data_plot, - yval = "Survival", - censor_show = TRUE, - xticks = xticks, xlab = "Days", ylab = "Survival Probability", - title = "tt", - footnotes = "ff" -) - -g_el <- h_decompose_gg(gg) -grid::grid.newpage() -grid.rect(gp = grid::gpar(lty = 1, col = "red", fill = "gray85", lwd = 5)) -grid::grid.draw(g_el$panel) - -grid::grid.newpage() -grid.rect(gp = grid::gpar(lty = 1, col = "royalblue", fill = "gray85", lwd = 5)) -grid::grid.draw(with(g_el, cbind(ylab, yaxis))) -} - } diff --git a/man/h_g_ipp.Rd b/man/h_g_ipp.Rd index 6b98016af0..b1c6e75110 100644 --- a/man/h_g_ipp.Rd +++ b/man/h_g_ipp.Rd @@ -1,25 +1,9 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/g_ipp.R, R/individual_patient_plot.R +% Please edit documentation in R/g_ipp.R \name{h_g_ipp} \alias{h_g_ipp} \title{Helper function to create simple line plot over time} \usage{ -h_g_ipp( - df, - xvar, - yvar, - xlab, - ylab, - id_var, - title = "Individual Patient Plots", - subtitle = "", - caption = NULL, - add_baseline_hline = FALSE, - yvar_baseline = "BASE", - ggtheme = nestcolor::theme_nest(), - col = NULL -) - h_g_ipp( df, xvar, @@ -67,17 +51,11 @@ by \code{ggplot2} to control outlook of plot. Use \code{ggplot2::theme()} to twe \item{col}{(\code{character})\cr line colors.} } \value{ -A \code{ggplot} line plot. - A \code{ggplot} line plot. } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} -Function that generates a simple line plot displaying parameter trends over time. - -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} - Function that generates a simple line plot displaying parameter trends over time. } \examples{ @@ -99,28 +77,7 @@ p <- h_g_ipp( ) p -library(dplyr) -library(nestcolor) - -# Select a small sample of data to plot. -adlb <- tern_ex_adlb \%>\% - filter(PARAMCD == "ALT", !(AVISIT \%in\% c("SCREENING", "BASELINE"))) \%>\% - slice(1:36) - -p <- h_g_ipp( - df = adlb, - xvar = "AVISIT", - yvar = "AVAL", - xlab = "Visit", - id_var = "USUBJID", - ylab = "SGOT/ALT (U/L)", - add_baseline_hline = TRUE -) -p - } \seealso{ -\code{\link[=g_ipp]{g_ipp()}} which uses this function. - \code{\link[=g_ipp]{g_ipp()}} which uses this function. } diff --git a/man/h_ggkm.Rd b/man/h_ggkm.Rd index 6fac344839..49abfe820d 100644 --- a/man/h_ggkm.Rd +++ b/man/h_ggkm.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/h_km.R, R/kaplan_meier_plot.R +% Please edit documentation in R/h_km.R \name{h_ggkm} \alias{h_ggkm} \title{Helper function to create a KM plot} @@ -11,25 +11,7 @@ h_ggkm( censor_show, xlab, ylab, - title, - footnotes = NULL, - max_time = NULL, - lwd = 1, - lty = NULL, - pch = 3, - size = 2, - col = NULL, - ci_ribbon = FALSE, - ggtheme = nestcolor::theme_nest() -) - -h_ggkm( - data, - xticks = NULL, - yval = "Survival", - censor_show, - xlab, - ylab, + ylim = NULL, title, footnotes = NULL, max_time = NULL, @@ -45,54 +27,52 @@ h_ggkm( \arguments{ \item{data}{(\code{data.frame})\cr survival data as pre-processed by \code{h_data_plot}.} -\item{xticks}{(\code{numeric}, \code{number}, or \code{NULL})\cr numeric vector of ticks or single number with spacing -between ticks on the x axis. If \code{NULL} (default), \code{\link[labeling:extended]{labeling::extended()}} is used to determine -an optimal tick position on the x axis.} +\item{xticks}{(\code{numeric} or \code{NULL})\cr numeric vector of tick positions or a single number with spacing +between ticks on the x-axis. If \code{NULL} (default), \code{\link[labeling:extended]{labeling::extended()}} is used to determine +optimal tick positions on the x-axis.} + +\item{yval}{(\code{string})\cr type of plot, to be plotted on the y-axis. Options are \code{Survival} (default) and \code{Failure} +probability.} -\item{yval}{(\code{string})\cr value of y-axis. Options are \code{Survival} (default) and \code{Failure} probability.} +\item{censor_show}{(\code{flag})\cr whether to show censored observations.} -\item{censor_show}{(\code{flag})\cr whether to show censored.} +\item{xlab}{(\code{string})\cr x-axis label.} -\item{xlab}{(\code{string})\cr label of x-axis.} +\item{ylab}{(\code{string})\cr y-axis label.} -\item{ylab}{(\code{string})\cr label of y-axis.} +\item{ylim}{(\code{numeric(2)})\cr vector containing lower and upper limits for the y-axis, respectively. +If \code{NULL} (default), the default scale range is used.} -\item{title}{(\code{string})\cr title for plot.} +\item{title}{(\code{string})\cr plot title.} -\item{footnotes}{(\code{string})\cr footnotes for plot.} +\item{footnotes}{(\code{string})\cr plot footnotes.} -\item{max_time}{(\code{numeric})\cr maximum value to show on X axis. Only data values less than or up to +\item{max_time}{(\code{numeric(1)})\cr maximum value to show on x-axis. Only data values less than or up to this threshold value will be plotted (defaults to \code{NULL}).} -\item{lwd}{(\code{numeric})\cr line width. Length of a vector should be equal -to number of strata from \code{\link[survival:survfit]{survival::survfit()}}.} +\item{lwd}{(\code{numeric})\cr line width. If a vector is given, its length should be equal to the number of strata from +\code{\link[survival:survfit]{survival::survfit()}}.} -\item{lty}{(\code{numeric})\cr line type. Length of a vector should be equal -to number of strata from \code{\link[survival:survfit]{survival::survfit()}}.} +\item{lty}{(\code{numeric})\cr line type. If a vector is given, its length should be equal to the number of strata from +\code{\link[survival:survfit]{survival::survfit()}}.} -\item{pch}{(\code{numeric}, \code{string})\cr value or character of points symbol to indicate censored cases.} +\item{pch}{(\code{string})\cr name of symbol or character to use as point symbol to indicate censored cases.} -\item{size}{(\code{numeric})\cr size of censored point, a class of \code{unit}.} +\item{size}{(\code{numeric(1)})\cr size of censored point symbols.} \item{col}{(\code{character})\cr lines colors. Length of a vector should be equal to number of strata from \code{\link[survival:survfit]{survival::survfit()}}.} -\item{ci_ribbon}{(\code{flag})\cr draw the confidence interval around the Kaplan-Meier curve.} +\item{ci_ribbon}{(\code{flag})\cr whether the confidence interval should be drawn around the Kaplan-Meier curve.} -\item{ggtheme}{(\code{theme})\cr a graphical theme as provided by \code{ggplot2} to control outlook of the Kaplan-Meier curve.} +\item{ggtheme}{(\code{theme})\cr a graphical theme as provided by \code{ggplot2} to format the Kaplan-Meier plot.} } \value{ -A \code{ggplot} object. - A \code{ggplot} object. } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} -Draw the Kaplan-Meier plot using \code{ggplot2}. - -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} - Draw the Kaplan-Meier plot using \code{ggplot2}. } \examples{ @@ -117,25 +97,4 @@ gg <- h_ggkm( gg } -\dontrun{ -library(dplyr) -library(survival) - -fit_km <- tern_ex_adtte \%>\% - filter(PARAMCD == "OS") \%>\% - survfit(form = Surv(AVAL, 1 - CNSR) ~ ARMCD, data = .) -data_plot <- h_data_plot(fit_km = fit_km) -xticks <- h_xticks(data = data_plot) -gg <- h_ggkm( - data = data_plot, - censor_show = TRUE, - xticks = xticks, - xlab = "Days", - yval = "Survival", - ylab = "Survival Probability", - title = "Survival" -) -gg -} - } diff --git a/man/h_grob_coxph.Rd b/man/h_grob_coxph.Rd index 4b3da65c8e..739887e7ed 100644 --- a/man/h_grob_coxph.Rd +++ b/man/h_grob_coxph.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/h_km.R, R/kaplan_meier_plot.R +% Please edit documentation in R/h_km.R \name{h_grob_coxph} \alias{h_grob_coxph} \title{Helper function to create Cox-PH grobs} @@ -8,43 +8,29 @@ h_grob_coxph( ..., x = 0, y = 0, - ttheme = gridExtra::ttheme_default(base_size = 12, padding = grid::unit(c(1, 0.5), - "lines"), core = list(bg_params = list(fill = c("grey95", "grey90"), alpha = 0.5))) -) - -h_grob_coxph( - ..., - x = 0, - y = 0, - ttheme = gridExtra::ttheme_default(base_size = 12, padding = grid::unit(c(1, 0.5), - "lines"), core = list(bg_params = list(fill = c("grey95", "grey90"), alpha = 0.5))) + width = grid::unit(0.4, "npc"), + ttheme = gridExtra::ttheme_default(padding = grid::unit(c(1, 0.5), "lines"), core = + list(bg_params = list(fill = c("grey95", "grey90"), alpha = 0.5))) ) } \arguments{ -\item{...}{arguments will be passed to \code{\link[=h_tbl_coxph_pairwise]{h_tbl_coxph_pairwise()}}.} - -\item{x}{(\code{numeric})\cr a value between 0 and 1 specifying x-location.} +\item{...}{arguments to pass to \code{\link[=h_tbl_coxph_pairwise]{h_tbl_coxph_pairwise()}}.} -\item{y}{(\code{numeric})\cr a value between 0 and 1 specifying y-location.} +\item{x}{(\code{proportion})\cr a value between 0 and 1 specifying x-location.} -\item{ttheme}{(\code{list})\cr see \code{\link[gridExtra:tableGrob]{gridExtra::ttheme_default()}}.} +\item{y}{(\code{proportion})\cr a value between 0 and 1 specifying y-location.} \item{width}{(\code{grid::unit})\cr width (as a unit) to use when printing the grob.} + +\item{ttheme}{(\code{list})\cr see \code{\link[gridExtra:tableGrob]{gridExtra::ttheme_default()}}.} } \value{ -A \code{grob} of a table containing statistics \code{HR}, \verb{XX\% CI} (\code{XX} taken from \code{control_coxph_pw}), -and \code{p-value (log-rank)}. - A \code{grob} of a table containing statistics \code{HR}, \verb{XX\% CI} (\code{XX} taken from \code{control_coxph_pw}), and \code{p-value (log-rank)}. } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} -Grob of \code{rtable} output from \code{\link[=h_tbl_coxph_pairwise]{h_tbl_coxph_pairwise()}} - -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} - Grob of \code{rtable} output from \code{\link[=h_tbl_coxph_pairwise]{h_tbl_coxph_pairwise()}} } \examples{ @@ -66,22 +52,4 @@ tbl_grob <- h_grob_coxph( grid::grid.draw(tbl_grob) } -\dontrun{ -library(dplyr) -library(survival) -library(grid) - -grid::grid.newpage() -grid.rect(gp = grid::gpar(lty = 1, col = "pink", fill = "gray85", lwd = 1)) -data <- tern_ex_adtte \%>\% - filter(PARAMCD == "OS") \%>\% - mutate(is_event = CNSR == 0) -tbl_grob <- h_grob_coxph( - df = data, - variables = list(tte = "AVAL", is_event = "is_event", arm = "ARMCD"), - control_coxph_pw = control_coxph(conf_level = 0.9), x = 0.5, y = 0.5 -) -grid::grid.draw(tbl_grob) -} - } diff --git a/man/h_grob_median_surv.Rd b/man/h_grob_median_surv.Rd index d72547c64f..b9bc0b4081 100644 --- a/man/h_grob_median_surv.Rd +++ b/man/h_grob_median_surv.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/h_km.R, R/kaplan_meier_plot.R +% Please edit documentation in R/h_km.R \name{h_grob_median_surv} \alias{h_grob_median_surv} \title{Helper function to create survival estimation grobs} @@ -9,43 +9,29 @@ h_grob_median_surv( armval = "All", x = 0.9, y = 0.9, - ttheme = gridExtra::ttheme_default() -) - -h_grob_median_surv( - fit_km, - armval = "All", - x = 0.9, - y = 0.9, + width = grid::unit(0.3, "npc"), ttheme = gridExtra::ttheme_default() ) } \arguments{ \item{fit_km}{(\code{survfit})\cr result of \code{\link[survival:survfit]{survival::survfit()}}.} -\item{armval}{(\code{string})\cr used as strata name when treatment arm variable only has one level. Default is "All".} +\item{armval}{(\code{string})\cr used as strata name when treatment arm variable only has one level. Default is \code{"All"}.} -\item{x}{(\code{numeric})\cr a value between 0 and 1 specifying x-location.} +\item{x}{(\code{proportion})\cr a value between 0 and 1 specifying x-location.} -\item{y}{(\code{numeric})\cr a value between 0 and 1 specifying y-location.} - -\item{ttheme}{(\code{list})\cr see \code{\link[gridExtra:tableGrob]{gridExtra::ttheme_default()}}.} +\item{y}{(\code{proportion})\cr a value between 0 and 1 specifying y-location.} \item{width}{(\code{grid::unit})\cr width (as a unit) to use when printing the grob.} + +\item{ttheme}{(\code{list})\cr see \code{\link[gridExtra:tableGrob]{gridExtra::ttheme_default()}}.} } \value{ -A \code{grob} of a table containing statistics \code{N}, \code{Median}, and \verb{XX\% CI} (\code{XX} taken from \code{fit_km}). - A \code{grob} of a table containing statistics \code{N}, \code{Median}, and \verb{XX\% CI} (\code{XX} taken from \code{fit_km}). } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} -The survival fit is transformed in a grob containing a table with groups in -rows characterized by N, median and 95\% confidence interval. - -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} - The survival fit is transformed in a grob containing a table with groups in rows characterized by N, median and 95\% confidence interval. } @@ -64,18 +50,4 @@ tern_ex_adtte \%>\% grid::grid.draw() } -\dontrun{ -library(dplyr) -library(survival) -library(grid) - -grid::grid.newpage() -grid.rect(gp = grid::gpar(lty = 1, col = "pink", fill = "gray85", lwd = 1)) -tern_ex_adtte \%>\% - filter(PARAMCD == "OS") \%>\% - survfit(form = Surv(AVAL, 1 - CNSR) ~ ARMCD, data = .) \%>\% - h_grob_median_surv() \%>\% - grid::grid.draw() -} - } diff --git a/man/h_grob_tbl_at_risk.Rd b/man/h_grob_tbl_at_risk.Rd index eaee69fff4..49c301cf1c 100644 --- a/man/h_grob_tbl_at_risk.Rd +++ b/man/h_grob_tbl_at_risk.Rd @@ -1,12 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/h_km.R, R/kaplan_meier_plot.R +% Please edit documentation in R/h_km.R \name{h_grob_tbl_at_risk} \alias{h_grob_tbl_at_risk} \title{Helper function to create patient-at-risk grobs} \usage{ -h_grob_tbl_at_risk(data, annot_tbl, xlim) - -h_grob_tbl_at_risk(data, annot_tbl, xlim) +h_grob_tbl_at_risk(data, annot_tbl, xlim, title = TRUE) } \arguments{ \item{data}{(\code{data.frame})\cr survival data as pre-processed by \code{h_data_plot}.} @@ -14,8 +12,8 @@ h_grob_tbl_at_risk(data, annot_tbl, xlim) \item{annot_tbl}{(\code{data.frame})\cr annotation as prepared by \code{\link[survival:summary.survfit]{survival::summary.survfit()}} which includes the number of patients at risk at given time points.} -\item{xlim}{(\code{numeric})\cr the maximum value on the x-axis (used to -ensure the at risk table aligns with the KM graph).} +\item{xlim}{(\code{numeric(1)})\cr the maximum value on the x-axis (used to ensure the at risk table aligns with the KM +graph).} \item{title}{(\code{flag})\cr whether the "Patients at Risk" title should be added above the \code{annot_at_risk} table. Has no effect if \code{annot_at_risk} is \code{FALSE}. Defaults to \code{TRUE}.} @@ -23,8 +21,6 @@ table. Has no effect if \code{annot_at_risk} is \code{FALSE}. Defaults to \code{ \value{ A named \code{list} of two \code{gTree} objects if \code{title = FALSE}: \code{at_risk} and \code{label}, or three \code{gTree} objects if \code{title = TRUE}: \code{at_risk}, \code{label}, and \code{title}. - -A named \code{list} of two \code{gTree} objects: \code{at_risk} and \code{label}. } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} @@ -32,11 +28,6 @@ A named \code{list} of two \code{gTree} objects: \code{at_risk} and \code{label} Two graphical objects are obtained, one corresponding to row labeling and the second to the table of numbers of patients at risk. If \code{title = TRUE}, a third object corresponding to the table title is also obtained. - -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} - -Two graphical objects are obtained, one corresponding to row labeling and -the second to the number of patient at risk. } \examples{ \donttest{ @@ -94,59 +85,4 @@ grid.rect(gp = grid::gpar(lty = 1, col = "green3", fill = "gray85", lwd = 1)) grid::grid.draw(tbl$label) } -\dontrun{ -library(dplyr) -library(survival) -library(grid) - -fit_km <- tern_ex_adtte \%>\% - filter(PARAMCD == "OS") \%>\% - survfit(form = Surv(AVAL, 1 - CNSR) ~ ARMCD, data = .) - -data_plot <- h_data_plot(fit_km = fit_km) - -xticks <- h_xticks(data = data_plot) - -gg <- h_ggkm( - data = data_plot, - censor_show = TRUE, - xticks = xticks, xlab = "Days", ylab = "Survival Probability", - title = "tt", footnotes = "ff", yval = "Survival" -) - -# The annotation table reports the patient at risk for a given strata and -# time (`xticks`). -annot_tbl <- summary(fit_km, time = xticks) -if (is.null(fit_km$strata)) { - annot_tbl <- with(annot_tbl, data.frame(n.risk = n.risk, time = time, strata = "All")) -} else { - strata_lst <- strsplit(sub("=", "equals", levels(annot_tbl$strata)), "equals") - levels(annot_tbl$strata) <- matrix(unlist(strata_lst), ncol = 2, byrow = TRUE)[, 2] - annot_tbl <- data.frame( - n.risk = annot_tbl$n.risk, - time = annot_tbl$time, - strata = annot_tbl$strata - ) -} - -# The annotation table is transformed into a grob. -tbl <- h_grob_tbl_at_risk(data = data_plot, annot_tbl = annot_tbl, xlim = max(xticks)) - -# For the representation, the layout is estimated for which the decomposition -# of the graphic element is necessary. -g_el <- h_decompose_gg(gg) -lyt <- h_km_layout(data = data_plot, g_el = g_el, title = "t", footnotes = "f") - -grid::grid.newpage() -pushViewport(viewport(layout = lyt, height = .95, width = .95)) -grid.rect(gp = grid::gpar(lty = 1, col = "purple", fill = "gray85", lwd = 1)) -pushViewport(viewport(layout.pos.row = 4, layout.pos.col = 2)) -grid.rect(gp = grid::gpar(lty = 1, col = "orange", fill = "gray85", lwd = 1)) -grid::grid.draw(tbl$at_risk) -popViewport() -pushViewport(viewport(layout.pos.row = 4, layout.pos.col = 1)) -grid.rect(gp = grid::gpar(lty = 1, col = "green3", fill = "gray85", lwd = 1)) -grid::grid.draw(tbl$label) -} - } diff --git a/man/h_grob_y_annot.Rd b/man/h_grob_y_annot.Rd index 8d2e0a224c..b12c15ba5b 100644 --- a/man/h_grob_y_annot.Rd +++ b/man/h_grob_y_annot.Rd @@ -1,11 +1,9 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/h_km.R, R/kaplan_meier_plot.R +% Please edit documentation in R/h_km.R \name{h_grob_y_annot} \alias{h_grob_y_annot} \title{Helper function to create grid object with y-axis annotation} \usage{ -h_grob_y_annot(ylab, yaxis) - h_grob_y_annot(ylab, yaxis) } \arguments{ @@ -15,16 +13,10 @@ h_grob_y_annot(ylab, yaxis) } \value{ A \code{gTree} object containing the y-axis annotation from a \code{ggplot}. - -a \code{gTree} object containing the y-axis annotation from a \code{ggplot}. } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} -Build the y-axis annotation from a decomposed \code{ggplot}. - -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} - Build the y-axis annotation from a decomposed \code{ggplot}. } \examples{ @@ -54,30 +46,4 @@ grid::grid.draw(h_grob_y_annot(ylab = g_el$ylab, yaxis = g_el$yaxis)) grid.rect(gp = grid::gpar(lty = 1, col = "gray35", fill = NA)) } -\dontrun{ -library(dplyr) -library(survival) -library(grid) - -fit_km <- tern_ex_adtte \%>\% - filter(PARAMCD == "OS") \%>\% - survfit(form = Surv(AVAL, 1 - CNSR) ~ ARMCD, data = .) -data_plot <- h_data_plot(fit_km = fit_km) -xticks <- h_xticks(data = data_plot) -gg <- h_ggkm( - data = data_plot, - censor_show = TRUE, - xticks = xticks, xlab = "Days", ylab = "Survival Probability", - title = "title", footnotes = "footnotes", yval = "Survival" -) - -g_el <- h_decompose_gg(gg) - -grid::grid.newpage() -pvp <- grid::plotViewport(margins = c(5, 4, 2, 20)) -pushViewport(pvp) -grid::grid.draw(h_grob_y_annot(ylab = g_el$ylab, yaxis = g_el$yaxis)) -grid.rect(gp = grid::gpar(lty = 1, col = "gray35", fill = NA)) -} - } diff --git a/man/h_km_layout.Rd b/man/h_km_layout.Rd index 8744b64e02..a84b8ca617 100644 --- a/man/h_km_layout.Rd +++ b/man/h_km_layout.Rd @@ -1,49 +1,42 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/h_km.R, R/kaplan_meier_plot.R +% Please edit documentation in R/h_km.R \name{h_km_layout} \alias{h_km_layout} \title{Helper function to prepare a KM layout} \usage{ -h_km_layout(data, g_el, title, footnotes, annot_at_risk = TRUE) - -h_km_layout(data, g_el, title, footnotes, annot_at_risk = TRUE) +h_km_layout( + data, + g_el, + title, + footnotes, + annot_at_risk = TRUE, + annot_at_risk_title = TRUE +) } \arguments{ \item{data}{(\code{data.frame})\cr survival data as pre-processed by \code{h_data_plot}.} \item{g_el}{(\code{list} of \code{gtable})\cr list as obtained by \code{h_decompose_gg()}.} -\item{title}{(\code{string})\cr title for plot.} +\item{title}{(\code{string})\cr plot title.} -\item{footnotes}{(\code{string})\cr footnotes for plot.} +\item{footnotes}{(\code{string})\cr plot footnotes.} \item{annot_at_risk}{(\code{flag})\cr compute and add the annotation table reporting the number of patient at risk matching the main grid of the Kaplan-Meier curve.} + +\item{annot_at_risk_title}{(\code{flag})\cr whether the "Patients at Risk" title should be added above the \code{annot_at_risk} +table. Has no effect if \code{annot_at_risk} is \code{FALSE}. Defaults to \code{TRUE}.} } \value{ -A grid layout. - A grid layout. } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} -Prepares a (5 rows) x (2 cols) layout for the Kaplan-Meier curve. - -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} - Prepares a (5 rows) x (2 cols) layout for the Kaplan-Meier curve. } \details{ -The layout corresponds to a grid of two columns and five rows of unequal dimensions. Most of the -dimension are fixed, only the curve is flexible and will accommodate with the remaining free space. -\itemize{ -\item The left column gets the annotation of the \code{ggplot} (y-axis) and the names of the strata for the patient -at risk tabulation. The main constraint is about the width of the columns which must allow the writing of -the strata name. -\item The right column receive the \code{ggplot}, the legend, the x-axis and the patient at risk table. -} - The layout corresponds to a grid of two columns and five rows of unequal dimensions. Most of the dimension are fixed, only the curve is flexible and will accommodate with the remaining free space. \itemize{ @@ -75,24 +68,4 @@ lyt <- h_km_layout(data = data_plot, g_el = g_el, title = "t", footnotes = "f") grid.show.layout(lyt) } -\dontrun{ -library(dplyr) -library(survival) - -fit_km <- tern_ex_adtte \%>\% - filter(PARAMCD == "OS") \%>\% - survfit(form = Surv(AVAL, 1 - CNSR) ~ ARMCD, data = .) -data_plot <- h_data_plot(fit_km = fit_km) -xticks <- h_xticks(data = data_plot) -gg <- h_ggkm( - data = data_plot, - censor_show = TRUE, - xticks = xticks, xlab = "Days", ylab = "Survival Probability", - title = "tt", footnotes = "ff", yval = "Survival" -) -g_el <- h_decompose_gg(gg) -lyt <- h_km_layout(data = data_plot, g_el = g_el, title = "t", footnotes = "f") -grid.show.layout(lyt) -} - } diff --git a/man/h_tbl_coxph_pairwise.Rd b/man/h_tbl_coxph_pairwise.Rd index f3e1c5cc30..2dbe3ad95c 100644 --- a/man/h_tbl_coxph_pairwise.Rd +++ b/man/h_tbl_coxph_pairwise.Rd @@ -1,12 +1,16 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/h_km.R, R/kaplan_meier_plot.R +% Please edit documentation in R/h_km.R \name{h_tbl_coxph_pairwise} \alias{h_tbl_coxph_pairwise} \title{Helper function for generating a pairwise Cox-PH table} \usage{ -h_tbl_coxph_pairwise(df, variables, control_coxph_pw = control_coxph()) - -h_tbl_coxph_pairwise(df, variables, control_coxph_pw = control_coxph()) +h_tbl_coxph_pairwise( + df, + variables, + ref_group_coxph = NULL, + control_coxph_pw = control_coxph(), + annot_coxph_ref_lbls = FALSE +) } \arguments{ \item{df}{(\code{data.frame})\cr data set containing all analysis variables.} @@ -16,16 +20,19 @@ h_tbl_coxph_pairwise(df, variables, control_coxph_pw = control_coxph()) \item \code{tte} (\code{numeric})\cr variable indicating time-to-event duration values. \item \code{is_event} (\code{logical})\cr event variable. \code{TRUE} if event, \code{FALSE} if time to event is censored. \item \code{arm} (\code{factor})\cr the treatment group variable. -\item \code{strat} (\code{character} or \code{NULL})\cr variable names indicating stratification factors. +\item \code{strata} (\code{character} or \code{NULL})\cr variable names indicating stratification factors. }} -\item{control_coxph_pw}{(\code{list})\cr parameters for comparison details, specified by using -the helper function \code{\link[=control_coxph]{control_coxph()}}. Some possible parameter options are: +\item{ref_group_coxph}{(\code{string} or \code{NULL})\cr level of arm variable to use as reference group in calculations for +\code{annot_coxph} table. If \code{NULL} (default), uses the first level of the arm variable.} + +\item{control_coxph_pw}{(\code{list})\cr parameters for comparison details, specified using the helper function +\code{\link[=control_coxph]{control_coxph()}}. Some possible parameter options are: \itemize{ \item \code{pval_method} (\code{string})\cr p-value method for testing hazard ratio = 1. -Default method is "log-rank", can also be set to "wald" or "likelihood". -\item \code{ties} (\code{string})\cr method for tie handling. Default is "efron", -can also be set to "breslow" or "exact". See more in \code{\link[survival:coxph]{survival::coxph()}} +Default method is \code{"log-rank"}, can also be set to \code{"wald"} or \code{"likelihood"}. +\item \code{ties} (\code{string})\cr method for tie handling. Default is \code{"efron"}, +can also be set to \code{"breslow"} or \code{"exact"}. See more in \code{\link[survival:coxph]{survival::coxph()}} \item \code{conf_level} (\code{proportion})\cr confidence level of the interval for HR. }} @@ -33,9 +40,6 @@ can also be set to "breslow" or "exact". See more in \code{\link[survival:coxph] \code{annot_coxph} table. If \code{FALSE} (default), only comparison groups will be printed in \code{annot_coxph} table labels.} } \value{ -A \code{data.frame} containing statistics \code{HR}, \verb{XX\% CI} (\code{XX} taken from \code{control_coxph_pw}), -and \code{p-value (log-rank)}. - A \code{data.frame} containing statistics \code{HR}, \verb{XX\% CI} (\code{XX} taken from \code{control_coxph_pw}), and \code{p-value (log-rank)}. } @@ -43,10 +47,6 @@ and \code{p-value (log-rank)}. \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} Create a \code{data.frame} of pairwise stratified or unstratified Cox-PH analysis results. - -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} - -Create a \code{data.frame} of pairwise stratified or unstratified CoxPH analysis results. } \examples{ library(dplyr) @@ -61,18 +61,4 @@ h_tbl_coxph_pairwise( control_coxph_pw = control_coxph(conf_level = 0.9) ) -\dontrun{ -library(dplyr) - -adtte <- tern_ex_adtte \%>\% - filter(PARAMCD == "OS") \%>\% - mutate(is_event = CNSR == 0) - -h_tbl_coxph_pairwise( - df = adtte, - variables = list(tte = "AVAL", is_event = "is_event", arm = "ARM"), - control_coxph_pw = control_coxph(conf_level = 0.9) -) -} - } diff --git a/man/h_tbl_median_surv.Rd b/man/h_tbl_median_surv.Rd index 13bcc8c0a0..06ab4c1817 100644 --- a/man/h_tbl_median_surv.Rd +++ b/man/h_tbl_median_surv.Rd @@ -1,30 +1,22 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/h_km.R, R/kaplan_meier_plot.R +% Please edit documentation in R/h_km.R \name{h_tbl_median_surv} \alias{h_tbl_median_surv} \title{Helper function for survival estimations} \usage{ -h_tbl_median_surv(fit_km, armval = "All") - h_tbl_median_surv(fit_km, armval = "All") } \arguments{ \item{fit_km}{(\code{survfit})\cr result of \code{\link[survival:survfit]{survival::survfit()}}.} -\item{armval}{(\code{string})\cr used as strata name when treatment arm variable only has one level. Default is "All".} +\item{armval}{(\code{string})\cr used as strata name when treatment arm variable only has one level. Default is \code{"All"}.} } \value{ -A summary table with statistics \code{N}, \code{Median}, and \verb{XX\% CI} (\code{XX} taken from \code{fit_km}). - A summary table with statistics \code{N}, \code{Median}, and \verb{XX\% CI} (\code{XX} taken from \code{fit_km}). } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} -Transform a survival fit to a table with groups in rows characterized by N, median and confidence interval. - -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} - Transform a survival fit to a table with groups in rows characterized by N, median and confidence interval. } \examples{ @@ -38,16 +30,4 @@ fit <- survfit( ) h_tbl_median_surv(fit_km = fit) -\dontrun{ -library(dplyr) -library(survival) - -adtte <- tern_ex_adtte \%>\% filter(PARAMCD == "OS") -fit <- survfit( - form = Surv(AVAL, 1 - CNSR) ~ ARMCD, - data = adtte -) -h_tbl_median_surv(fit_km = fit) -} - } diff --git a/man/h_xticks.Rd b/man/h_xticks.Rd index 4c799d80e8..a304f50ca9 100644 --- a/man/h_xticks.Rd +++ b/man/h_xticks.Rd @@ -1,37 +1,27 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/h_km.R, R/kaplan_meier_plot.R +% Please edit documentation in R/h_km.R \name{h_xticks} \alias{h_xticks} \title{Helper function to calculate x-tick positions} \usage{ -h_xticks(data, xticks = NULL, max_time = NULL) - h_xticks(data, xticks = NULL, max_time = NULL) } \arguments{ \item{data}{(\code{data.frame})\cr survival data as pre-processed by \code{h_data_plot}.} -\item{xticks}{(\code{numeric}, \code{number}, or \code{NULL})\cr numeric vector of ticks or single number with spacing -between ticks on the x axis. If \code{NULL} (default), \code{\link[labeling:extended]{labeling::extended()}} is used to determine -an optimal tick position on the x axis.} +\item{xticks}{(\code{numeric} or \code{NULL})\cr numeric vector of tick positions or a single number with spacing +between ticks on the x-axis. If \code{NULL} (default), \code{\link[labeling:extended]{labeling::extended()}} is used to determine +optimal tick positions on the x-axis.} -\item{max_time}{(\code{numeric})\cr maximum value to show on X axis. Only data values less than or up to +\item{max_time}{(\code{numeric(1)})\cr maximum value to show on x-axis. Only data values less than or up to this threshold value will be plotted (defaults to \code{NULL}).} } \value{ -A vector of positions to use for x-axis ticks on a \code{ggplot} object. - A vector of positions to use for x-axis ticks on a \code{ggplot} object. } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} -Calculate the positions of ticks on the x-axis. However, if \code{xticks} already -exists it is kept as is. It is based on the same function \code{ggplot2} relies on, -and is required in the graphic and the patient-at-risk annotation table. - -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} - Calculate the positions of ticks on the x-axis. However, if \code{xticks} already exists it is kept as is. It is based on the same function \code{ggplot2} relies on, and is required in the graphic and the patient-at-risk annotation table. @@ -52,21 +42,4 @@ h_xticks(data, xticks = 500, max_time = 6000) h_xticks(data, xticks = c(0, 500), max_time = 300) h_xticks(data, xticks = 500, max_time = 300) -\dontrun{ -library(dplyr) -library(survival) - -data <- tern_ex_adtte \%>\% - filter(PARAMCD == "OS") \%>\% - survfit(form = Surv(AVAL, 1 - CNSR) ~ ARMCD, data = .) \%>\% - h_data_plot() - -h_xticks(data) -h_xticks(data, xticks = seq(0, 3000, 500)) -h_xticks(data, xticks = 500) -h_xticks(data, xticks = 500, max_time = 6000) -h_xticks(data, xticks = c(0, 500), max_time = 300) -h_xticks(data, xticks = 500, max_time = 300) -} - } diff --git a/man/try_car_anova.Rd b/man/try_car_anova.Rd index a81cde8287..b3ba87bf83 100644 --- a/man/try_car_anova.Rd +++ b/man/try_car_anova.Rd @@ -9,12 +9,12 @@ try_car_anova(mod, test.statistic) \arguments{ \item{mod}{\code{lm}, \code{aov}, \code{glm}, \code{multinom}, \code{polr} \code{mlm}, \code{coxph}, \code{coxme}, \code{lme}, \code{mer}, \code{merMod}, \code{svyglm}, \code{svycoxph}, - \code{rlm}, or other suitable model object.} + \code{rlm}, \code{clm}, \code{clmm}, or other suitable model object.} \item{test.statistic}{for a generalized linear model, whether to calculate \code{"LR"} (likelihood-ratio), \code{"Wald"}, or \code{"F"} tests; for a Cox or Cox mixed-effects model, whether to calculate \code{"LR"} (partial-likelihood ratio) or - \code{"Wald"} tests; in the default case or for linear mixed models fit by + \code{"Wald"} tests (with \code{"LR"} tests unavailable for Cox models using the \code{tt} argument); in the default case or for linear mixed models fit by \code{lmer}, whether to calculate Wald \code{"Chisq"} or Kenward-Roger \code{"F"} tests with Satterthwaite degrees of freedom (\emph{warning:} the KR F-tests can be very time-consuming).