Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upCapture the risk table as a data frame #158
Comments
|
Now,
Fit survival curves and plot library(survival)
fit <- survfit( Surv(time, status) ~ sex, data = lung )
library(survminer)
ggsurv <- ggsurvplot(fit, data = lung,
risk.table = TRUE,
cumevents = TRUE,
palette = "jco",
tables.height = 0.15, # specify tables height
tables.y.text = FALSE, # hide tables y axis text
ggtheme = theme_gray(), # main theme
tables.theme = theme_cleantable()
)
print(ggsurv)Get the data used to create survival curves # Use this:
data.survplot <- ggsurv$data.survplot
# Or this:
data.survplot <- surv_summary(fit, data = lung)
head(data.survplot)time n.risk n.event n.censor surv std.err upper lower strata sex 1 11 138 3 0 0.9782609 0.01268978 1.0000000 0.9542301 sex=1 1 2 12 135 1 0 0.9710145 0.01470747 0.9994124 0.9434235 sex=1 1 3 13 134 2 0 0.9565217 0.01814885 0.9911586 0.9230952 sex=1 1 4 15 132 1 0 0.9492754 0.01967768 0.9866017 0.9133612 sex=1 1 5 26 131 1 0 0.9420290 0.02111708 0.9818365 0.9038355 sex=1 1 6 30 130 1 0 0.9347826 0.02248469 0.9768989 0.8944820 sex=1 1 Get the data used to create tables risk table, cumulative number of event table, cumulative number of censoring table. data.survtable <- ggsurv$data.survtable
data.survtablestrata time n.risk pct.risk n.event cum.n.event n.censor cum.n.censor strata_size sex 1 sex=1 0 138 100 0 0 0 0 138 1 2 sex=1 250 62 45 65 65 11 11 138 1 3 sex=1 500 20 14 31 96 11 22 138 1 4 sex=1 750 7 5 13 109 0 22 138 1 5 sex=1 1000 2 1 3 112 2 24 138 1 6 sex=2 0 90 100 0 0 0 0 90 2 7 sex=2 250 53 59 24 24 13 13 90 2 8 sex=2 500 21 23 18 42 14 27 90 2 9 sex=2 750 3 3 10 52 8 35 90 2 10 sex=2 1000 0 0 1 53 2 37 90 2 > |

(e-mail from a user)
I would like to capture the at risk table as a data frame, looking more or less like what is printed at the bottom of the graph. In the returned list from ggplotsurv the table portion of the list is actually a graph; that isn't want I want. Is there a way to capture the table itself.