3

I'm trying to plot survival curves for a corresponding analysis using survminer & survival packages. Setting risk.table = TRUE in the ggsurvplot command results in a warning saying 'Vectorized input to element_text() is not officially supported. Results may be unexpected or may change in future versions of ggplot2.'

I also tried whether this issue occurs with other data which it does. Here's a simple reprex I ran on R version 4.0.3, Rstudio Version 1.2.5033:

library('survival')
library('survminer')
library('ggplot2')

lung <- survival::lung
fit<- survfit(Surv(time, status) ~ sex, data = lung)
ggsurvplot(fit, data = lung, risk.table = TRUE)

The warning doesn't occur if risk.table = FALSE which is why I assume that the risktables argument somehow interferes with the ggplot2 x-axis formatting. In a discussion on github about whether vectorized input to element_text() should be supported in the future of ggplot2, developers seem to rather opt for a deprecation cycle https://github.com/tidyverse/ggplot2/issues/3492.

I was wondering if there currently is some way to overcome this issue since I would want to make regular use of ggsurvplot and its risktables feature in the future. The issue also seems to occur for other plots created with ggplot2 (see github discussion above). However, in the reprex, it seems to be related to an inherent argument of ggsurvplot which to me seems critical for future use of this function. Any supportive input would be highly appreciated.

GRowInG
  • 357
  • 3
  • 14
  • This is a great question but it might be better asked on the RStudio community forums where you are more likely to get attention from one of the ggplot2 developers directly – qdread Feb 23 '21 at 14:28
  • Thanks for the hint! On the Rstudio community page @hadley says: 'It’s easiest to say what community.rstudio.com is not: it’s not a replacement for Stack Overflow, GitHub, or our premium support services: If you have a precisely and clearly defined question (and accompanying reprex), you should still ask it on Stack Overflow.' For the time being, let's see if we can learn something about this issue here on Stack Overflow, if not, I'll gladly be following your advice. – GRowInG Feb 23 '21 at 14:45
  • Both earlier comments are reasonable. But rather than posting to RStudio support, wouldn't contacting the authors of `survminer` be just as worthwhile? It's their risk table that's causing the issue, after all... – Limey Feb 23 '21 at 15:09
  • I have the same issue with `combine=T` instead of `risk.table=T`. – Vincent Mar 09 '21 at 13:11
  • Have you tried ```ggsurvplot_combine()``` as alternative? – GRowInG Mar 10 '21 at 14:12

1 Answers1

1

Here is a workaround to get the information from the risk.table feature and present it (and a little more information) next to the survival plot. I guess until the issue is solved by the authors that's the best we can do about it for now.

library('survival')
library('survminer')
library('ggplot2')
library('kableExtra')


# Specify dataset
lung <- survival::lung
fit<- survfit(Surv(time, status) ~ sex, data = lung)


# -----------Scenario 1: KM-plot and risk.table without writing a function

kmplot <- ggsurvplot(fit, data = lung, risk.table = FALSE)
risktable <- kmplot$data.survtable


# Using R Markdown: Setting results='asis' in the corresponding chunk header - knit to html
## Output KM-plot
kmplot

## Output risktable
print (
  kable(risktable, caption = paste("Survival stratified by sex")) %>%
    column_spec(1, bold = T) %>%
    kable_styling(bootstrap_options = "hover", full_width = TRUE))



# -----------Scenario 2: Using a function
fun_surv <- function (x) {
kmplot <- ggsurvplot(x, data = lung, risk.table = FALSE)
risktable <- kmplot$data.survtable
list_surv <- list(kmplot, risktable)
list_surv
}

res_surv <- fun_surv(fit)


# Using R Markdown: Setting results='asis' in the corresponding chunk header - knit to html
## Output KM-plot
res_surv[[1]]

## Output risktable
print (
  kable(res_surv [[2]], caption = paste("Survival stratified by sex")) %>%
    column_spec(1, bold = T) %>%
    kable_styling(bootstrap_options = "hover", full_width = TRUE))
GRowInG
  • 357
  • 3
  • 14