diff --git a/R/ggsurvplot_core.R b/R/ggsurvplot_core.R index 23fe85a..ebe8f96 100644 --- a/R/ggsurvplot_core.R +++ b/R/ggsurvplot_core.R @@ -435,12 +435,12 @@ ggsurvplot_core <- function(fit, data = NULL, fun = NULL, h_line_data <- data.frame(x = 0, y = max(df$y2), xend = max(df$x1), yend = max(df$y2)) p <- p + geom_segment(aes(x = .data$x, y = .data$y, xend = .data$xend, yend = .data$yend), - data = h_line_data, linetype = linetype, size = size, color = color) # horizontal segment + data = h_line_data, linetype = linetype, linewidth = size, color = color) # horizontal segment } if(type %in% c("hv", "v")) p <- p + geom_segment(aes(x = .data$x1, y = .data$y1, xend = .data$x2, yend = .data$y2), data = df, - linetype = linetype, size = size, color = color) # vertical segments + linetype = linetype, linewidth = size, color = color) # vertical segments } else warning("Median survival not reached.") } diff --git a/R/ggsurvplot_df.R b/R/ggsurvplot_df.R index 6dc4f43..e506e54 100644 --- a/R/ggsurvplot_df.R +++ b/R/ggsurvplot_df.R @@ -177,7 +177,7 @@ ggsurvplot_df <- function(fit, fun = NULL, df[, .strata.var] <- factor( df[, .strata.var], levels = .levels(.strata), labels = legend.labs) p <- ggplot2::ggplot(df, ggplot2::aes(x = !!sym("time"), y = !!sym("surv"))) + - ggpubr::geom_exec(surv.geom, data = df, size = size, color = color, linetype = linetype, ...) + + ggpubr::geom_exec(surv.geom, data = df, linewidth = size, color = color, linetype = linetype, ...) + ggplot2::scale_y_continuous(breaks = y.breaks, labels = scale_labels, limits = ylim, expand = .expand) + ggplot2::coord_cartesian(xlim = xlim)+ ggtheme diff --git a/R/utilities.R b/R/utilities.R index 1fc2025..ff50f7b 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -21,6 +21,11 @@ is_pkg_version_sup<- function(pkg, version){ cc } +# shim for ggplot2 prior to 3.5.2 +if (!exists("is_ggplot") && exists("is.ggplot")) { + is_ggplot <- is.ggplot +} + # Count the number of ggplots in a list .count_ggplots <- function(list.objects){ nplot <- 0 diff --git a/tests/testthat/test-ggsurvplot_basic.R b/tests/testthat/test-ggsurvplot_basic.R new file mode 100644 index 0000000..e8fe864 --- /dev/null +++ b/tests/testthat/test-ggsurvplot_basic.R @@ -0,0 +1,25 @@ +test_that("basic KM plot runs without {lifecycle} warnings", { + rlang::local_options(lifecycle_verbosity = "warning") + + expect_no_warning( + { + ggsurvplot( + fit = survfit(Surv(time = time, event = status) ~ x, data = aml), + surv.median.line = "hv" + ) + }, + class = "lifecycle_warning_deprecated" + ) +}) + +test_that("basic KM plot runs without {lifecycle} errors", { + expect_no_error( + { + ggsurvplot( + fit = survfit(Surv(time = time, event = status) ~ x, data = aml), + surv.median.line = "hv" + ) + }, + class = "lifecycle_error_deprecated" + ) +})