[R] 2 KM curves on the same plot

Marc Schwartz
Tue, 29 Sep 2020 14:08:37 -0000

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 at
r-project.org> wrote: