I am trying to plot Kaplan-Meyer curve using ggsurvplot from survminer package. I'm unable to plot it when I pass a survfit object saved in a list.
Let me use lung dataset as a example. Everything works below:
library("survival")
library("survminer")
fit <- survfit(Surv(time, status) ~ sex, data = lung)
ggsurvplot(fit,
conf.int = TRUE,
risk.table.col = "strata",
palette = c("#E7B800", "#2E9FDF"),
xlim = c(0, 600))
Now I do survfit on two variables and save the model result in a list. Then tried to make KM plot with ggsurvplot.
vars <- c('sex', 'ph.ecog')
l<- map (vars, ~survfit(Surv(time, status)~ get(.x),data = lung ))
l<- set_names(l, vars)
ggsurvplot(l$sex,
conf.int = TRUE,
risk.table.col = "strata",
palette = c("#E7B800", "#2E9FDF"),
xlim = c(0, 600))
I got error message like this:
Error in eval(inp, data, env) : object '.x' not found
Does someone know why? How can I fix this problem? Thanks a lot!