From 18f05718f3f7fdd863eed7dec53a52da8d7fcaf2 Mon Sep 17 00:00:00 2001 From: Daniel Sjoberg Date: Tue, 7 May 2024 15:29:43 -0700 Subject: [PATCH 1/4] updates --- DESCRIPTION | 4 +-- NEWS.md | 4 ++- R/tidy_survfit.R | 6 ++-- .../cuminc2-censor-mark-all-outcomes.svg | 34 +++++++++---------- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b4fa794..0f6136b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: ggsurvfit Title: Flexible Time-to-Event Figures -Version: 1.0.0.9001 +Version: 1.0.0.9002 Authors@R: c( person("Daniel D.", "Sjoberg", , "danield.sjoberg@gmail.com", role = c("aut", "cre", "cph"), comment = c(ORCID = "0000-0003-0862-2018")), @@ -33,7 +33,7 @@ Imports: gtable, patchwork (>= 1.1.0), rlang (>= 1.0.0), - survival (>= 3.4-0), + survival (>= 3.6-4), tidyr (>= 1.0.0) Suggests: covr, diff --git a/NEWS.md b/NEWS.md index c78c0d8..9888cc0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,12 +2,14 @@ * For multi-state models created with `survfit()`, the y-axis label is now "Probability in State". (#205) -* Updated legend position syntax to account for changes in ggplot v3.5.0. +* Updated legend position syntax to account for changes in {ggplot2} v3.5.0. * The `tidy_survfit()` (and subsequently `ggsurvfit()`) now honor the `survfit(start.time)` if specified. (#192) * We now allow for negative follow-up times in `tidy_survfit()` (and subsequently `ggsurvfit()`). When negative follow-up times are present users should specify `survfit(start.time)` and we print a note to this effect when not set. (#192) +* As of {survival} v3.6-4, the number censored are now returned as a matrix for multi-state models (i.e. competing risks models). The `tidy_survfit()` function has been updated to account for this new structure and the minimum version of {survival} has been increased to the latest version. + # ggsurvfit 1.0.0 * By default, a model plot created with `ggsurvfit()` or `ggcuminc()` uses the color aesthetic to plot curves by the stratifying variable(s), and further, `ggcuminc()` uses the linetype aesthetic for plots that contain multiple outcomes (i.e. competing events). We now introduce the global option `"ggsurvfit.switch-color-linetype"` to switch these defaults, giving users more flexibility over the output figures. Furthermore, when the `linetype_aes=` argument is called in a situation when it does not apply, it will be silently ignored (previously, an error message _may_ have been thrown). (#166) diff --git a/R/tidy_survfit.R b/R/tidy_survfit.R index c445354..0850820 100644 --- a/R/tidy_survfit.R +++ b/R/tidy_survfit.R @@ -57,12 +57,12 @@ tidy_survfit <- function(x, df_tidy <- df_tidy %>% dplyr::filter(!.data$state %in% "(s0)") %>% - dplyr::select(-dplyr::all_of("n.risk")) %>% + dplyr::select(-dplyr::all_of(c("n.risk", "n.censor"))) %>% dplyr::left_join( - df_tidy %>% dplyr::filter(.data$state %in% "(s0)") %>% dplyr::select(dplyr::any_of(c("strata", "time", "n.risk"))), + df_tidy %>% dplyr::filter(.data$state %in% "(s0)") %>% dplyr::select(dplyr::any_of(c("strata", "time", "n.risk", "n.censor"))), by = intersect(c("strata", "time"), names(df_tidy)) ) %>% - dplyr::relocate("n.risk", .after = "time") %>% + dplyr::relocate(dplyr::any_of(c("n.risk", "n.censor")), .after = "time") %>% dplyr::rename(outcome = "state") } diff --git a/tests/testthat/_snaps/add_censor_mark/cuminc2-censor-mark-all-outcomes.svg b/tests/testthat/_snaps/add_censor_mark/cuminc2-censor-mark-all-outcomes.svg index 9e3287b..b8e97f1 100644 --- a/tests/testthat/_snaps/add_censor_mark/cuminc2-censor-mark-all-outcomes.svg +++ b/tests/testthat/_snaps/add_censor_mark/cuminc2-censor-mark-all-outcomes.svg @@ -426,24 +426,24 @@ 25 Months to Death/Censor Cumulative Incidence - + - - - -death from cancer -death other causes - - - - - - - - - -Drug A -Drug B + + + + + + + +Drug A +Drug B + + + + + +death from cancer +death other causes cuminc2-censor_mark-all-outcomes From 46f2f662b96b28222104ad5aba4b45fee97b7ac5 Mon Sep 17 00:00:00 2001 From: Daniel Sjoberg Date: Tue, 7 May 2024 15:31:16 -0700 Subject: [PATCH 2/4] Update NEWS.md --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 9888cc0..7a20a59 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,7 +8,7 @@ * We now allow for negative follow-up times in `tidy_survfit()` (and subsequently `ggsurvfit()`). When negative follow-up times are present users should specify `survfit(start.time)` and we print a note to this effect when not set. (#192) -* As of {survival} v3.6-4, the number censored are now returned as a matrix for multi-state models (i.e. competing risks models). The `tidy_survfit()` function has been updated to account for this new structure and the minimum version of {survival} has been increased to the latest version. +* As of {survival} v3.6-4, the number censored are now returned as a matrix for multi-state models (i.e. competing risks models). The `tidy_survfit()` function has been updated to account for this new structure and the minimum version of {survival} has been increased to the latest version. (#199) # ggsurvfit 1.0.0 From f418bfa08c81303d59677e12918bf9747f5e85f0 Mon Sep 17 00:00:00 2001 From: Daniel Sjoberg Date: Tue, 7 May 2024 15:41:14 -0700 Subject: [PATCH 3/4] updates --- inst/WORDLIST | 2 + man/stepribbon.Rd | 47 +++++++-- ...minc2-confidence-interval-all-outcomes.svg | 34 +++---- .../cuminc2-quantile-all-outcomes.svg | 26 ++--- .../cuminc2-risktable-all-outcomes.svg | 26 ++--- .../cuminc2-ggcuminc-all-outcomes.svg | 26 ++--- .../cuminc2-ggcuminc-sf-all-outcomes.svg | 26 ++--- .../ggci-outcomes-linetype.new.svg | 97 ------------------- .../ggci-strata-outcomes.svg | 34 +++---- 9 files changed, 127 insertions(+), 191 deletions(-) delete mode 100644 tests/testthat/_snaps/ggsurvfit_options/ggci-outcomes-linetype.new.svg diff --git a/inst/WORDLIST b/inst/WORDLIST index 56254b7..a0b8c1d 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -17,6 +17,7 @@ adjuvant behaviour cowplot cuminc +geom's geoms geom’ ggcuminc @@ -39,6 +40,7 @@ survfit tablemab tibble tidycmprsk +unmapped unremarkably unstratified vismab diff --git a/man/stepribbon.Rd b/man/stepribbon.Rd index 4a0a12e..107c8a3 100644 --- a/man/stepribbon.Rd +++ b/man/stepribbon.Rd @@ -47,10 +47,18 @@ from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{geom}{which geom to use; defaults to "\code{ribbon}"} -\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{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{na.rm}{If \code{FALSE}, the default, missing values are removed with a warning. If \code{TRUE}, missing values are silently removed.} @@ -69,10 +77,33 @@ 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()}}. 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.} +\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. +}} } \value{ a ggplot2 figure diff --git a/tests/testthat/_snaps/add_confidence_interval/cuminc2-confidence-interval-all-outcomes.svg b/tests/testthat/_snaps/add_confidence_interval/cuminc2-confidence-interval-all-outcomes.svg index 8cef958..217a17d 100644 --- a/tests/testthat/_snaps/add_confidence_interval/cuminc2-confidence-interval-all-outcomes.svg +++ b/tests/testthat/_snaps/add_confidence_interval/cuminc2-confidence-interval-all-outcomes.svg @@ -90,24 +90,24 @@ 25 Months to Death/Censor Cumulative Incidence - + - - - - - -death from cancer -death other causes - - - - - - - -Drug A -Drug B + + + + + +Drug A +Drug B + + + + + + + +death from cancer +death other causes cuminc2-confidence_interval-all-outcomes diff --git a/tests/testthat/_snaps/add_quantile/cuminc2-quantile-all-outcomes.svg b/tests/testthat/_snaps/add_quantile/cuminc2-quantile-all-outcomes.svg index b8c4784..fab1310 100644 --- a/tests/testthat/_snaps/add_quantile/cuminc2-quantile-all-outcomes.svg +++ b/tests/testthat/_snaps/add_quantile/cuminc2-quantile-all-outcomes.svg @@ -79,20 +79,20 @@ 25 Months to Death/Censor Cumulative Incidence - + - - - -death from cancer -death other causes - - - - - -Drug A -Drug B + + + +Drug A +Drug B + + + + + +death from cancer +death other causes cuminc2-quantile-all-outcomes diff --git a/tests/testthat/_snaps/add_risktable/cuminc2-risktable-all-outcomes.svg b/tests/testthat/_snaps/add_risktable/cuminc2-risktable-all-outcomes.svg index 3342784..eb40f33 100644 --- a/tests/testthat/_snaps/add_risktable/cuminc2-risktable-all-outcomes.svg +++ b/tests/testthat/_snaps/add_risktable/cuminc2-risktable-all-outcomes.svg @@ -183,20 +183,20 @@ - + - - - -death from cancer -death other causes - - - - - -Drug A -Drug B + + + +Drug A +Drug B + + + + + +death from cancer +death other causes diff --git a/tests/testthat/_snaps/ggcuminc/cuminc2-ggcuminc-all-outcomes.svg b/tests/testthat/_snaps/ggcuminc/cuminc2-ggcuminc-all-outcomes.svg index 65e26da..aef9c0f 100644 --- a/tests/testthat/_snaps/ggcuminc/cuminc2-ggcuminc-all-outcomes.svg +++ b/tests/testthat/_snaps/ggcuminc/cuminc2-ggcuminc-all-outcomes.svg @@ -74,20 +74,20 @@ 25 Months to Death/Censor Cumulative Incidence - + - - - -death from cancer -death other causes - - - - - -Drug A -Drug B + + + +Drug A +Drug B + + + + + +death from cancer +death other causes cuminc2-ggcuminc-all-outcomes diff --git a/tests/testthat/_snaps/ggcuminc/cuminc2-ggcuminc-sf-all-outcomes.svg b/tests/testthat/_snaps/ggcuminc/cuminc2-ggcuminc-sf-all-outcomes.svg index 756d8dd..add8005 100644 --- a/tests/testthat/_snaps/ggcuminc/cuminc2-ggcuminc-sf-all-outcomes.svg +++ b/tests/testthat/_snaps/ggcuminc/cuminc2-ggcuminc-sf-all-outcomes.svg @@ -74,20 +74,20 @@ 25 Months to Death/Censor Cumulative Incidence - + - - - -death from cancer -death other causes - - - - - -Drug A -Drug B + + + +Drug A +Drug B + + + + + +death from cancer +death other causes cuminc2-ggcuminc_sf-all-outcomes diff --git a/tests/testthat/_snaps/ggsurvfit_options/ggci-outcomes-linetype.new.svg b/tests/testthat/_snaps/ggsurvfit_options/ggci-outcomes-linetype.new.svg deleted file mode 100644 index 52ae3a3..0000000 --- a/tests/testthat/_snaps/ggsurvfit_options/ggci-outcomes-linetype.new.svg +++ /dev/null @@ -1,97 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -0.0 -0.1 -0.2 -0.3 - - - - - - - - - - -0 -5 -10 -15 -20 -25 -Months to Death/Censor -Cumulative Incidence - - - - - - - - - - - -death from cancer -death other causes -ggci_outcomes_linetype - - diff --git a/tests/testthat/_snaps/ggsurvfit_options/ggci-strata-outcomes.svg b/tests/testthat/_snaps/ggsurvfit_options/ggci-strata-outcomes.svg index f179ec0..41b74f1 100644 --- a/tests/testthat/_snaps/ggsurvfit_options/ggci-strata-outcomes.svg +++ b/tests/testthat/_snaps/ggsurvfit_options/ggci-strata-outcomes.svg @@ -431,24 +431,24 @@ 25 Months to Death/Censor Cumulative Incidence - + - - - - - - - -death from cancer -death other causes - - - - - -Drug A -Drug B + + + +Drug A +Drug B + + + + + + + + + +death from cancer +death other causes ggci_strata_outcomes From a79539108b4611677f59f71a1e843cd252ee2bea Mon Sep 17 00:00:00 2001 From: Daniel Sjoberg Date: Tue, 7 May 2024 15:44:24 -0700 Subject: [PATCH 4/4] Update ggcuminc.R --- R/ggcuminc.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/ggcuminc.R b/R/ggcuminc.R index d357654..bdb75cd 100644 --- a/R/ggcuminc.R +++ b/R/ggcuminc.R @@ -1,5 +1,6 @@ #' Plot Cumulative Incidence #' +#' @description #' Plot a cumulative incidence object created with `tidycmprsk::cuminc()` #' or a multi-state object created with `survfit2()`. #' Read more on multi-state models [here](https://cran.r-project.org/package=survival/vignettes/compete.pdf).