diff --git a/R/ggcuminc.R b/R/ggcuminc.R index ab182f6..ecbaf2d 100644 --- a/R/ggcuminc.R +++ b/R/ggcuminc.R @@ -55,6 +55,14 @@ ggcuminc <- function(x, outcome = NULL, ) } + # Generate an error if the input is a `survfit.coxphms` regression model: ---- + if (inherits(x, "survfitcoxms")) { + cli_abort( + "Argument {.arg x} does not support {.cls survfit.coxphms} object. + Please fit a multi-state model with another project, such as {.fn coxph}." + ) + } + # prep data to be passed to ggplot() ----------------------------------------- if (inherits(x, "tidycuminc")) df <- tidy_cuminc(x = x) @@ -69,7 +77,7 @@ ggcuminc <- function(x, outcome = NULL, cli_inform("Plotting outcome {.val {outcome}}.") } if (any(!outcome %in% unique(df$outcome))) { - cli_abort("Argument {.code outcome} must be one or more of {.val {unique(df$outcome)}}") + cli_abort("Argument {.arg x} does not support {.cls survfit.coxphms} object.") } df <- dplyr::filter(df, .data$outcome %in% .env$outcome) diff --git a/R/scale_ggsurvfit.R b/R/scale_ggsurvfit.R index 4947f2f..7acda91 100644 --- a/R/scale_ggsurvfit.R +++ b/R/scale_ggsurvfit.R @@ -34,8 +34,23 @@ #' # specify additional scales #' ggsurvfit + #' scale_ggsurvfit(x_scales = list(breaks = seq(0, 8, by = 2))) +#' +#' @details +#' Specical case: in the risk table, large numbers (with more than 4 digits) may not +#' be shown completely, with some digits truncated outside the plot region. +#' To remedy this, consider the following example code for a simulated large-size survival dataset: +#' Here, adjust the expand size in `scale_ggsurvfit(x_scales = list(expand = c(0.05, 0)))` (for example) +#' can modify the position of numbers in the risk table +#' and make them all fit in the plot region. The scale of the `expand` argument differs by cases. +#' +#' df_colon_large <- df_colon[sample(1:nrow(df_colon), size = 15*nrow(df_colon), replace = TRUE), ] +#' ggsurvfit <- +#' survfit2(Surv(time, status) ~ surg, data = df_colon_large) %>% +#' ggsurvfit() + add_risktable() + +#' scale_ggsurvfit() #' @inherit ggsurvfit seealso -scale_ggsurvfit <- function(x_scales = list(), y_scales = list()){ +scale_ggsurvfit <- + function(x_scales = list(), y_scales = list()){ scale_ggsurvfit_empty_list <- list() structure(scale_ggsurvfit_empty_list, x_scales = x_scales, y_scales = y_scales, class = "scale_ggsurvfit") } diff --git a/R/utils-add_risktable.R b/R/utils-add_risktable.R index ff07d43..ffd3a28 100644 --- a/R/utils-add_risktable.R +++ b/R/utils-add_risktable.R @@ -18,7 +18,7 @@ } # get data to place in risktables -------------------------------------------- - times <- times %||% plot_build$layout$panel_params[[1]]$x.sec$breaks + times <- times %||% plot_build$layout$panel_params[[1]]$x$breaks df_times <- .prepare_data_for_risk_tables(data = x$data, times = times, combine_groups = combine_groups) diff --git a/man/scale_ggsurvfit.Rd b/man/scale_ggsurvfit.Rd index 72ece39..8c998f5 100644 --- a/man/scale_ggsurvfit.Rd +++ b/man/scale_ggsurvfit.Rd @@ -30,6 +30,20 @@ For example, it's common you'll need to specify the x-axis break points. To reset any of the above settings to their ggplot2 default, set the value to \code{NULL}, e.g. \code{y_scales = list(limits = NULL)}. } +\details{ +Specical case: in the risk table, large numbers (with more than 4 digits) may not +be shown completely, with some digits truncated outside the plot region. +To remedy this, consider the following example code for a simulated large-size survival dataset: +Here, adjust the expand size in \code{scale_ggsurvfit(x_scales = list(expand = c(0.05, 0)))} (for example) +can modify the position of numbers in the risk table +and make them all fit in the plot region. The scale of the \code{expand} argument differs by cases. + +df_colon_large <- df_colon\link{sample(1:nrow(df_colon), size = 15*nrow(df_colon), replace = TRUE), } +ggsurvfit <- +survfit2(Surv(time, status) ~ surg, data = df_colon_large) \%>\% +ggsurvfit() + add_risktable() + +scale_ggsurvfit() +} \examples{ ggsurvfit <- survfit2(Surv(time, status) ~ surg, data = df_colon) \%>\% @@ -42,6 +56,7 @@ ggsurvfit + scale_ggsurvfit() # specify additional scales ggsurvfit + scale_ggsurvfit(x_scales = list(breaks = seq(0, 8, by = 2))) + } \seealso{ Visit the \href{https://www.danieldsjoberg.com/ggsurvfit/articles/gallery.html}{gallery} for examples modifying the default figures diff --git a/man/stepribbon.Rd b/man/stepribbon.Rd index 107c8a3..4a0a12e 100644 --- a/man/stepribbon.Rd +++ b/man/stepribbon.Rd @@ -47,18 +47,10 @@ from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{geom}{which geom to use; defaults to "\code{ribbon}"} -\item{position}{A position adjustment to use on the data for this layer. This -can be used in various ways, including to prevent overplotting and -improving the display. The \code{position} argument accepts the following: -\itemize{ -\item The result of calling a position function, such as \code{position_jitter()}. -This method allows for passing extra arguments to the position. -\item A string naming the position adjustment. To give the position as a -string, strip the function name of the \code{position_} prefix. For example, -to use \code{position_jitter()}, give the position as \code{"jitter"}. -\item For more information and other ways to specify the position, see the -\link[ggplot2:layer_positions]{layer position} documentation. -}} +\item{position}{Position adjustment, either as a string naming the adjustment +(e.g. \code{"jitter"} to use \code{position_jitter}), or the result of a call to a +position adjustment function. Use the latter if you need to change the +settings of the adjustment.} \item{na.rm}{If \code{FALSE}, the default, missing values are removed with a warning. If \code{TRUE}, missing values are silently removed.} @@ -77,33 +69,10 @@ the default plot specification, e.g. \code{\link[ggplot2:borders]{borders()}}.} \item{direction}{\code{hv} for horizontal-vertical steps, \code{vh} for vertical-horizontal steps} -\item{...}{Other arguments passed on to \code{\link[ggplot2:layer]{layer()}}'s \code{params} argument. These -arguments broadly fall into one of 4 categories below. Notably, further -arguments to the \code{position} argument, or aesthetics that are required -can \emph{not} be passed through \code{...}. Unknown arguments that are not part -of the 4 categories below are ignored. -\itemize{ -\item Static aesthetics that are not mapped to a scale, but are at a fixed -value and apply to the layer as a whole. For example, \code{colour = "red"} -or \code{linewidth = 3}. The geom's documentation has an \strong{Aesthetics} -section that lists the available options. The 'required' aesthetics -cannot be passed on to the \code{params}. Please note that while passing -unmapped aesthetics as vectors is technically possible, the order and -required length is not guaranteed to be parallel to the input data. -\item When constructing a layer using -a \verb{stat_*()} function, the \code{...} argument can be used to pass on -parameters to the \code{geom} part of the layer. An example of this is -\code{stat_density(geom = "area", outline.type = "both")}. The geom's -documentation lists which parameters it can accept. -\item Inversely, when constructing a layer using a -\verb{geom_*()} function, the \code{...} argument can be used to pass on parameters -to the \code{stat} part of the layer. An example of this is -\code{geom_area(stat = "density", adjust = 0.5)}. The stat's documentation -lists which parameters it can accept. -\item The \code{key_glyph} argument of \code{\link[ggplot2:layer]{layer()}} may also be passed on through -\code{...}. This can be one of the functions described as -\link[ggplot2:draw_key]{key glyphs}, to change the display of the layer in the legend. -}} +\item{...}{Other arguments passed on to \code{\link[ggplot2:layer]{layer()}}. These are +often aesthetics, used to set an aesthetic to a fixed value, like +\code{colour = "red"} or \code{size = 3}. They may also be parameters +to the paired geom/stat.} } \value{ a ggplot2 figure