Skip to content

Commit

Permalink
updating y-axis labels (#206)
Browse files Browse the repository at this point in the history
* updating y-axis labels

* Update test-ggcuminc.R

* Update test-ggcuminc.R

* Update test-ggcuminc.R
  • Loading branch information
ddsjoberg authored Apr 25, 2024
1 parent b2defc6 commit 5db4896
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 5 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# ggsurvfit (development version)

* 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.

* The `tidy_survfit()` (and subsequently `ggsurvfit()`) now honor the `survfit(start.time)` if specified. (#192)
Expand Down
12 changes: 9 additions & 3 deletions R/tidy_survfit.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ tidy_survfit <- function(x,
df_tidy <- .keep_selected_times(df_tidy, times = times)

# transform survival estimate as specified
df_tidy <- .transform_estimate(df_tidy, type = type)
df_tidy <- .transform_estimate(df_tidy, type = type, survfit = x)

# improve strata label, if possible
df_tidy <- .construct_strata_label(df_tidy, survfit = x)
Expand Down Expand Up @@ -170,7 +170,7 @@ tidy_survfit <- function(x,
gsub(pattern = "(\\W)", replacement = "\\\\\\1", x = x)
}

.transform_estimate <- function(x, type) {
.transform_estimate <- function(x, type, survfit) {
# select transformation function ---------------------------------------------
if (rlang::is_string(type)) {
.transfun <-
Expand Down Expand Up @@ -209,7 +209,13 @@ tidy_survfit <- function(x,
estimate_type_label =
dplyr::case_when(
rlang::is_string(.env$type) && .env$type %in% "survival" ~ "Survival Probability",
rlang::is_string(.env$type) && .env$type %in% "cuminc" ~ "Cumulative Incidence",
rlang::is_string(.env$type) &&
.env$type %in% "cuminc" &&
!is.null(.env$survfit$transitions) &&
sum(apply(.env$survfit$transitions, MARGIN = 1, FUN = sum) > 0L) == 1L ~ "Cumulative Incidence",
rlang::is_string(.env$type) &&
.env$type %in% "cuminc" &&
!is.null(.env$survfit$transitions) ~ "Probability in State",
rlang::is_string(.env$type) && .env$type %in% "risk" ~ "Risk",
rlang::is_string(.env$type) && .env$type %in% "cumhaz" ~ "Cumulative Hazard",
TRUE ~ rlang::expr_deparse(.transfun)
Expand Down
13 changes: 11 additions & 2 deletions man/survfit2.Rd

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

Loading

0 comments on commit 5db4896

Please sign in to comment.