Skip to content

Add xticks, xlim, and ylim arguments to g_lineplot #1244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Added `facet_var` to `g_lineplot` to allow plot faceting by a factor variable.
* Updated `g_lineplot` legend to follow factor levels set by users.
* Added examples and tests for `label_all` parameter to `extract_survival_biomarkers` and `extract_survival_subgroups`.
* Added the `xticks`, `xlim`, and `ylim` arguments to `g_lineplot` to allow for customization of the x and y axes.

### Bug Fixes
* Fixed bug in `s_ancova` that prevented statistics from being printed when arm levels include special characters.
Expand Down
5 changes: 5 additions & 0 deletions R/argument_convention.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
#' @param vars (`character`)\cr variable names for the primary analysis variable to be iterated over.
#' @param var (`string`)\cr single variable name for the primary analysis variable.
#' @param x (`numeric`)\cr vector of numbers we want to analyze.
#' @param xlim (`numeric(2)`)\cr vector containing lower and upper limits for the x-axis, respectively.
#' If `NULL` (default), the default scale range is used.
#' @param ylim (`numeric(2)`)\cr vector containing lower and upper limits for the y-axis, respectively.
#' If `NULL` (default), the default scale range is used.
#'
#'
#' @details Although this function just returns `NULL` it has two uses, for
#' the `tern` users it provides a documentation of arguments that are
Expand Down
4 changes: 1 addition & 3 deletions R/g_km.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' including the number of patient at risk at given time and the median survival
#' per group.
#'
#' @param df (`data.frame`)\cr data set containing all analysis variables.
#' @inheritParams argument_convention
#' @param variables (named `list`)\cr variable names. Details are:
#' * `tte` (`numeric`)\cr variable indicating time-to-event duration values.
#' * `is_event` (`logical`)\cr event variable. `TRUE` if event, `FALSE` if time to event is censored.
Expand Down Expand Up @@ -35,8 +35,6 @@
#' @param yval (`string`)\cr type of plot, to be plotted on the y-axis. Options are `Survival` (default) and `Failure`
#' probability.
#' @param ylab (`string`)\cr y-axis label.
#' @param ylim (`numeric(2)`)\cr vector containing lower and upper limits for the y-axis, respectively.
#' If `NULL` (default), the minimum and maximum y-values displayed are used as limits.
#' @param title (`string`)\cr plot title.
#' @param footnotes (`string`)\cr plot footnotes.
#' @param font_size (`numeric(1)`)\cr font size to use for all text.
Expand Down
19 changes: 16 additions & 3 deletions R/g_lineplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#'
#' Line plot with the optional table.
#'
#' @param df (`data.frame`)\cr data set containing all analysis variables.
#' @inheritParams argument_convention
#' @param alt_counts_df (`data.frame` or `NULL`)\cr data set that will be used (only)
#' to counts objects in groups for stratification.
#' @param variables (named `character`) vector of variable names in `df` which should include:
Expand Down Expand Up @@ -46,6 +46,9 @@
#' @param legend_position (`string`)\cr the position of the plot legend (`"none"`, `"left"`, `"right"`, `"bottom"`,
#' `"top"`, or a two-element numeric vector).
#' @param ggtheme (`theme`)\cr a graphical theme as provided by `ggplot2` to control styling of the plot.
#' @param xticks (`numeric` or `NULL`)\cr numeric vector of tick positions or a single number with spacing
#' between ticks on the x-axis, for use when `variables$x` is numeric. If `NULL` (default), [labeling::extended()] is
#' used to determine optimal tick positions on the x-axis. If `variables$x` is not numeric, this argument is ignored.
#' @param x_lab (`string` or `NULL`)\cr x-axis label. If `NULL` then no label will be added.
#' @param y_lab (`string` or `NULL`)\cr y-axis label. If `NULL` then no label will be added.
#' @param y_lab_add_paramcd (`flag`)\cr whether `paramcd`, i.e. `unique(df[[variables["paramcd"]]])` should be added
Expand Down Expand Up @@ -140,6 +143,9 @@ g_lineplot <- function(df,
legend_title = NULL,
legend_position = "bottom",
ggtheme = nestcolor::theme_nest(),
xticks = NULL,
xlim = NULL,
ylim = NULL,
x_lab = obj_label(df[[variables[["x"]]]]),
y_lab = NULL,
y_lab_add_paramcd = TRUE,
Expand All @@ -158,7 +164,9 @@ g_lineplot <- function(df,
checkmate::assert_character(mid, null.ok = TRUE)
checkmate::assert_character(interval, null.ok = TRUE)
checkmate::assert_character(col, null.ok = TRUE)

checkmate::assert_numeric(xticks, null.ok = TRUE)
checkmate::assert_numeric(xlim, finite = TRUE, any.missing = FALSE, len = 2, sorted = TRUE, null.ok = TRUE)
checkmate::assert_numeric(ylim, finite = TRUE, any.missing = FALSE, len = 2, sorted = TRUE, null.ok = TRUE)
checkmate::assert_string(title, null.ok = TRUE)
checkmate::assert_string(subtitle, null.ok = TRUE)

Expand Down Expand Up @@ -353,8 +361,13 @@ g_lineplot <- function(df,
}
}

if (is.numeric(df_stats[[x]])) {
if (length(xticks) == 1) xticks <- seq(from = min(df_stats[[x]]), to = max(df_stats[[x]]), by = xticks)
p <- p + ggplot2::scale_x_continuous(breaks = if (!is.null(xticks)) xticks else waiver(), limits = xlim)
}

p <- p +
ggplot2::scale_y_continuous(labels = scales::comma) +
ggplot2::scale_y_continuous(labels = scales::comma, limits = ylim) +
ggplot2::labs(
title = title,
subtitle = subtitle,
Expand Down
6 changes: 6 additions & 0 deletions man/argument_convention.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/g_km.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions man/g_lineplot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/h_ggkm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading