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
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:> > 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 at 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.
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: > > 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 at 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.
Thank you very much Jim, this is great!! 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:> > 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 at 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.
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,>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: > > 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 at 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.
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:> > 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 at 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.