Hi Jim, I tried points(-1,-1) before lines() and before clip(), but either way, it still shows everything, :-(
It's interesting that the examples with hist() provided by the R help of clip function works nicely. I also tried a simple linear regression plots below, clip() works, too. dat<-data.frame(x=1:10,y=1:10) fit<-lm(y~x,dat) plot(1:10) abline(fit) xylim<-par("usr") clip(6,xylim[2],xylim[3],xylim[4]) abline(fit,col=2) ## yes, it only shows the fit line from 6 to the right lines(c(2,8),c(5,5)) ## yes, it only shows the line from 6 to the right So it's puzzling that only when using lines() with a survfit() object (ovarian example below), somehow clip() doesn't work John On Tuesday, September 29, 2020, 07:58:53 PM PDT, Jim Lemon <drjimle...@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 <arrayprof...@yahoo.com> wrote: > > 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 > <drjimle...@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@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@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. > ______________________________________________ R-help@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.