Skip to content
Prev 385841 / 398503 Next

2 KM curves on the same plot

Hi Jim,

I tried the clip() function below, surprisingly it did not work! I read the R help file and feel your script should work. To have a workable example, I used the ovarian dataset in the survival package as an example:

ovarian1<-ovarian
ovarian1$fustat[ovarian$futime>450]<-0
ovarian1$futime[ovarian$futime>450]<-450

ovarian2<-subset(ovarian,futime>450)

fit1 <- survfit(Surv(futime, fustat) ~ rx, data = ovarian1)
fit2 <- survfit(Surv(futime, fustat) ~ rx, data = ovarian2)

plot(fit1, xlim=c(0,1200), col = 1:2)
abline(v=450)
xylim<-par("usr")
clip(450,xylim[2],xylim[3],xylim[4])
lines(fit2, col = 3:4,lty=2)

I can still see that the extra horizontal line on the top.?

Can you or anyone have any suggestion what went wrong?

Thanks,

John
On Tuesday, September 29, 2020, 01:35:48 AM PDT, Jim Lemon <drjimlemon at gmail.com> wrote:
Hi John,
Perhaps the most direct way would be:

plot(fit1, col=1:2)
xylim<-par("usr")
clip(4,xylim[2],xylim[3],xylim[4])
lines(fit2,col=1:2)

Remember that the new clipping rectangle will persist until you or
something else resets it.

Jim

On Tue, Sep 29, 2020 at 10:34 AM array chip via R-help
<r-help at r-project.org> wrote: