Skip to content
Prev 385830 / 398503 Next

2 KM curves on the same plot

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 at me.com> wrote:
Hi John,
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