0

I am trying to include table in the survival plot. but I get an error as

Error in `annotate()`:
! Can't find geom called "table"
Traceback:

1. annotate(geom = "table", x = 140, y = 0.9, label = list(as.data.frame(table)))
2. layer(geom = geom, params = list(na.rm = na.rm, ...), stat = StatIdentity, 
 .     position = PositionIdentity, data = data, mapping = aes_all(names(data)), 
 .     inherit.aes = FALSE, show.legend = FALSE)
3. check_subclass(geom, "Geom", env = parent.frame(), call = call_env)
4. cli::cli_abort("Can't find {argname} called {.val {x}}", call = call)
5. rlang::abort(message, ..., call = call, use_cli_format = TRUE, 
 .     .frame = .frame)
6. signal_abort(cnd, .file)

The code I executed is:

library(survival)
library(survminer)

data(aml)
aml$x <- as.character(aml$x)
aml[10,3] <- 'SuperMaintained'
aml[11,3] <- 'SuperMaintained'
aml[22,3] <- 'SuperMaintained'
aml[23,3] <- 'SuperMaintained'
aml$x <- factor(aml$x, levels = c('Nonmaintained','Maintained','SuperMaintained'))


fit <- survfit(Surv(time, status) ~ x, data = aml)

res=pairwise_survdiff(Surv(time, status) ~ x, data = aml)
table <- res$p.value

p1 <- ggsurvplot(fit, conf.int = FALSE, surv.median.line = c('hv'), data = aml,  pval = TRUE, risk.table = FALSE) 

p1$plot + annotate(geom = "table", x = 140, y = 0.9, label = list(as.data.frame(table)))

0 Answers0