What I have is a Kaplan-Meier Analysis of patients with mechanical heart support using R.
What I need is adding the following data into the plot (like in the example):
- patients who survived due to a heart transplantation (HTX)
- patients who died
In other words, there are two groups where one is a subset (transplanted patients) of the other (all patients). These two curves must start at 0/0 and will increase.
My own plot is done by:
pump <- read.table(file=datafile, header=FALSE,
col.names=c('TIME', 'CENSUS', 'DEVICE'))
# convert days to months
pump$TIME <- pump$TIME/(730/24)
mfit.overall <- survfit(Surv(TIME, CENSUS==0) ~ 1, data=pump)
plot(mfit.overall, xlab="months on device", ylab="cum. survival", xaxt="n")
axis(1, at=seq(from=0, to=24, by=6), las=0)
How may I add the two additional curves?
Kind Regards Johann
Sample Kaplan Meier Curve: http://i.stack.imgur.com/158e8.jpg
Demo Data:
Survival Data, which goes into pump:
TIME CENSUS DEVICE 426 1 1 349 1 1 558 1 1 402 1 1 12 0 1 84 0 1 308 1 1 174 1 1 315 1 1 734 1 1 544 1 2 1433 1 2 1422 1 2 262 1 2 318 1 2 288 1 2 1000 1 2
TX data:
TIME CENSUS DEVICE 426 1 1 288 1 2 308 1 1
deaths:
TIME CENSUS DEVICE 12 0 1 84 0 1
par(new=TRUE)
is a useful hack, I think @Gavin has the better answer. If I had known about it I would also have solved it his way. – Backlin