From 45d99e46ad11a6742795602d1aced79c246b2f3a Mon Sep 17 00:00:00 2001 From: Alboukadel Kassambara Date: Tue, 2 Sep 2025 22:22:04 +0200 Subject: [PATCH 1/2] Fix ggplot2 3.5.0 aesthetic length warning for median lines (#643) - Resolve warning when using surv.median.line = "hv"/"h" with multiple curves - Create single-row dataframe for horizontal line to avoid scalar aesthetic with multi-row data --- NEWS.md | 1 + R/ggsurvplot_core.R | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index 24a15ff..2c36205 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,6 +8,7 @@ ## Bug fixes +- Fix ggplot2 3.5.0 aesthetic length warning when using `surv.median.line = "hv"` or `"h"` with multiple survival curves (#643) - Fix compatibility with ggplot2 development version (#681): Remove manual class assignment in `theme_survminer()` to ensure proper theme object construction - Fix test suite compatibility with ggplot2 development version (#681): Update layer access syntax in tests to support both stable (`$layers`) and development (`@layers`) versions - Fix "Ignoring unknown labels" warnings by conditionally setting legend titles only for aesthetics that are actually used in plots diff --git a/R/ggsurvplot_core.R b/R/ggsurvplot_core.R index 3d9d92f..78b2ee1 100644 --- a/R/ggsurvplot_core.R +++ b/R/ggsurvplot_core.R @@ -412,10 +412,13 @@ ggsurvplot_core <- function(fit, data = NULL, fun = NULL, df <- stats::na.omit(df) if(nrow(df)>0){ - if(type %in% c("hv", "h")) + if(type %in% c("hv", "h")){ + # Create single-row dataframe for horizontal line to avoid aesthetic length warning + 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 = 0, y = max(y2), xend = max(x1), yend = max(y2)), - data = df, linetype = linetype, size = size, color = color) # horizontal segment + geom_segment(aes(x = x, y = y, xend = xend, yend = yend), + data = h_line_data, linetype = linetype, size = size, color = color) # horizontal segment + } if(type %in% c("hv", "v")) p <- p + geom_segment(aes(x = x1, y = y1, xend = x2, yend = y2), data = df, From c8959ce820322e896ac336fd6b4c6e47f7fff94e Mon Sep 17 00:00:00 2001 From: Alboukadel Kassambara Date: Tue, 2 Sep 2025 22:22:23 +0200 Subject: [PATCH 2/2] doc updated --- man/ggsurvtheme.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/ggsurvtheme.Rd b/man/ggsurvtheme.Rd index aa2f412..50e4e26 100644 --- a/man/ggsurvtheme.Rd +++ b/man/ggsurvtheme.Rd @@ -72,7 +72,7 @@ ggsurv <- ggsurvplot(fit, data = lung, risk.table = TRUE, # Change font size, style and color at the same time # Use font.x = 14, to change only font size; or use # font.x = "bold", to change only font face. -ggsurv \%+\% theme_survminer( +ggsurv \%++\% theme_survminer( font.main = c(16, "bold", "darkblue"), font.submain = c(15, "bold.italic", "purple"), font.caption = c(14, "plain", "orange"),