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, 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"),