Skip to content
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

Add ylim argument to g_km #1001

Merged
merged 1 commit into from
Jul 6, 2023
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 @@ -2,6 +2,7 @@

### Enhancements
* Added method for `character` class to `h_coxreg_inter_effect` enabling `character` covariates in `summarize_coxreg`.
* Added `ylim` argument to `g_km` to allow the user to set custom limits for the y-axis.

### Enhancements
* Started deprecation cycle for `summarize_vars` and `control_summarize_vars`. Renamed into `analyze_vars` and `control_analyze_vars` to reflect underlying `rtables` machinery while keeping backward compatibility with aliases.
Expand Down
7 changes: 6 additions & 1 deletion R/kaplan_meier_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#' @param censor_show (`flag`)\cr whether to show censored.
#' @param xlab (`string`)\cr label of x-axis.
#' @param ylab (`string`)\cr label of y-axis.
#' @param ylim (`vector` of `numeric`)\cr vector of length 2 containing lower and upper limits for the y-axis.
#' @param title (`string`)\cr title for plot.
#' @param footnotes (`string`)\cr footnotes for plot.
#' @param col (`character`)\cr lines colors. Length of a vector should be equal
Expand Down Expand Up @@ -181,6 +182,7 @@ g_km <- function(df,
xlab = "Days",
yval = c("Survival", "Failure"),
ylab = paste(yval, "Probability"),
ylim = c(0, 1),
title = NULL,
footnotes = NULL,
draw = TRUE,
Expand Down Expand Up @@ -246,6 +248,7 @@ g_km <- function(df,
xlab = xlab,
yval = yval,
ylab = ylab,
ylim = ylim,
title = title,
footnotes = footnotes,
max_time = max_time,
Expand Down Expand Up @@ -631,6 +634,7 @@ h_ggkm <- function(data,
censor_show,
xlab,
ylab,
ylim = c(0, 1),
title,
footnotes = NULL,
max_time = NULL,
Expand All @@ -643,6 +647,7 @@ h_ggkm <- function(data,
ggtheme = nestcolor::theme_nest()) {
checkmate::assert_numeric(lty, null.ok = TRUE)
checkmate::assert_character(col, null.ok = TRUE)
checkmate::assert_numeric(ylim, finite = TRUE, any.missing = FALSE, len = 2, sorted = TRUE)

# change estimates of survival to estimates of failure (1 - survival)
if (yval == "Failure") {
Expand Down Expand Up @@ -683,7 +688,7 @@ h_ggkm <- function(data,
}

gg <- gg +
ggplot2::coord_cartesian(ylim = c(0, 1)) +
ggplot2::coord_cartesian(ylim = ylim) +
ggplot2::labs(x = xlab, y = ylab, title = title, caption = footnotes)

if (!is.null(col)) {
Expand Down
3 changes: 3 additions & 0 deletions man/g_km.Rd

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

3 changes: 3 additions & 0 deletions man/h_ggkm.Rd

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