[R] 2 KM curves on the same plot

array chip @rr@ypro|||e @end|ng |rom y@hoo@com
Tue Sep 29 19:05:56 CEST 2020


Thank you Marc as well! I'll try both ways! Yes this is an oncology study with time set at 5

John


On Tuesday, September 29, 2020, 07:08:39 AM PDT, Marc Schwartz <marc_schwartz using me.com> wrote: 





Hi John,

>From the looks of the first plot, it would appear that perhaps you are engaged in a landmark analysis in an oncology setting, with the landmark time set at 5 years. On the off chance that you are not familiar with the pros and cons of that methodology, Google "landmark analysis", which should yield a number of references.

With respect to the plot itself, here is one approach, in addition to the one that Jim suggested. This will use a 1 x 2 matrix of plot regions, and adjust the various axes accordingly.

library(survival)

## Create two models with the same data for this use, the second adding 150 to the event times
## to mimic a landmark time at 150 weeks

fit <- survfit(Surv(time, status) ~ x, data = aml)
fit2 <- survfit(Surv(time, status) ~ x, data = aml)
fit2$time <- fit2$time + 150

## create the x 1 x 2 plot matrix
par(mfrow = c(1, 2))

## Set the plot region margins so there is no space to the right
par(mar = c(4, 4, 4, 0))

## Fix the plot limits for consistency
## xaxs = "i" removes the default 4% extensions to the plot region limits
plot(fit, axes = FALSE, xlim = c(0, 150), ylim = c(0, 1), xaxs = "i")

axis(1, at = seq(0, 150, 50), line = -1)
axis(2, las = 1)

## Set the plot region margins so there is no space to the left
par(mar = c(4, 0, 4, 4))

## Set the plot limits for the second time interval
plot(fit2, axes = FALSE, xlim = c(150, 300), ylim = c(0, 1), xaxs = "i")

axis(1, at = seq(150, 300, 50), line = -1)
axis(4, las = 1)

## Draw the vertical line at 150 weeks
axis(2, at = seq(0, 1, 0.2), labels = FALSE, lty = "dashed")


Regards,

Marc Schwartz


> On Sep 28, 2020, at 8:33 PM, array chip via R-help <r-help using r-project.org> wrote:
> 
> Hello,
> 
> Can anyone suggest a simple way to generate a Kaplan-Meier plot with 2 survfit objects, just like this one: 
> 
> https://drive.google.com/file/d/1fEcpdIdE2xYtA6LBQN9ck3JkL6-goabX/view?usp=sharing
> 
> Suppose I have 2 survfit objects: fit1 is for the curve on the left (survtime has been truncated to the cutoff line: year 5), fit2 is for the curve on the right (minimum survival time is at the cutoff line: year 5), but if I do the following:
> 
> plot(fit1, col=1:2)
> lines(fit2,col=1:2)
> 
> Then I will have an horizontal line on the top that connect from 0 to 4 years, which I do not want that to be drawn (see blue arrow below):
> 
> https://drive.google.com/file/d/178mQGlhnaOg9PA-oE-W_W5CtrGD03ljH/view?usp=sharing
> 
> Can anyone have a strategy to make this kind of plot happen?
> 
> Thanks,
> 
> John

> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list