Skip to content
Prev 385844 / 398503 Next

2 KM curves on the same plot

Jim,

I tried a few things, I found that clip() works if I just do some regular graphing tasks. But as long as I run lines(fit) with "fit" object is a survfit object, this would reset to default plot region. See the ovarian example below:

library(survival)
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")
points(-1,-1)
clip(450,xylim[2],xylim[3],xylim[4])
abline(h=0.5,col=2)? ? ? ### YES, clipping() works!

lines(fit2, col = 3:4,lty=2)? ### clipping does not work! reset to default plot region
abline(h=0.4,col=2)? ? ? ?### NO, clipping() does not work!

So disappointed with this, otherwise this would be such a simple method to do what I want.

Thanks,

John

On Tuesday, September 29, 2020, 07:58:53 PM PDT, Jim Lemon <drjimlemon at gmail.com> wrote:?

Hi John,
I should have remembered this. For some reason, the clip() function
doesn't operate until you have issued a graphics command. Try:

points(-1,-1)

before calling lines()

Jim
On Wed, Sep 30, 2020 at 12:26 PM array chip <arrayprofile at yahoo.com> wrote: