Laura Bonnett
2009-Jun-09 14:36 UTC
[R] Isolating a single plot from plots produced simultaneously
Dear R-Help, I am using the 'mfp' package. It produces three plots (as I am using the Cox model) simultaneously which can be viewed together using the following code: fit <- mfp(Surv(rem.Remtime,rem.Rcens)~fp(age)+strata(rpa),family=cox,data=nearma,select=0.05,verbose=TRUE) par(mfrow=c(2,2)) plot(fit) They can be viewed separately but the return key must be pressed after each graph appears (Click or hit ENTER for next page). I'd like to isolate the second plot produced (the estimated functional form of the influence of age on the log relative hazard) so that I can use the 'points' function to add the linear predictors for the untransformed and the log-transformed models. In the usual situation one would produce a plot and then type: coxfitu <- coxph(Surv(rem.Remtime,rem.Rcens)~age+strata(rpa),data=nearma) points(coxfitu$linear.predictor,col=2) coxfitl <- coxph(Surv(rem.Remtime,rem.Rcens)~log(age)+strata(rpa),data=nearma) points(coxfitl$linear.predictor,col=3) Can anyone tell me how to isolate just the second plot produced? Thank you for your help, Laura
David Winsemius
2009-Jun-09 15:23 UTC
[R] Isolating a single plot from plots produced simultaneously
This is almost certainly a device-dependent issue, which is the reason the Posting Guide requests that you include such details. On a Mac using the GUI interface, one can scroll backwards through the graphics windows with <cmd>-<left arrow>. With the plot of interest as the focus one can then issue additonal plotting function calls such as lines() or points() and then save the plots as pdf if the default Qartz device has been used. I suspect there are equivalent facilities for Windows and Linux installations and encourage you to try reading the help pages: ?Devices #should bring up useful (installation-specific) information -- David On Jun 9, 2009, at 10:36 AM, Laura Bonnett wrote:> Dear R-Help, > > I am using the 'mfp' package. It produces three plots (as I am using > the Cox model) simultaneously which can be viewed together using the > following code: > > fit <- mfp(Surv(rem.Remtime,rem.Rcens)~fp(age) > +strata(rpa),family=cox,data=nearma,select=0.05,verbose=TRUE) > par(mfrow=c(2,2)) > plot(fit) > > They can be viewed separately but the return key must be pressed after > each graph appears (Click or hit ENTER for next page). > > I'd like to isolate the second plot produced (the estimated functional > form of the influence of age on the log relative hazard) so that I can > use the 'points' function to add the linear predictors for the > untransformed and the log-transformed models. In the usual situation > one would produce a plot and then type: > > coxfitu <- coxph(Surv(rem.Remtime,rem.Rcens)~age > +strata(rpa),data=nearma) > points(coxfitu$linear.predictor,col=2) > coxfitl <- coxph(Surv(rem.Remtime,rem.Rcens)~log(age) > +strata(rpa),data=nearma) > points(coxfitl$linear.predictor,col=3) > > Can anyone tell me how to isolate just the second plot produced? > > Thank you for your help, > > Laura > > ______________________________________________ > R-help at r-project.org mailing list > 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.David Winsemius, MD Heritage Laboratories West Hartford, CT
Thomas Lumley
2009-Jun-09 16:24 UTC
[R] Isolating a single plot from plots produced simultaneously
On Tue, 9 Jun 2009, Laura Bonnett wrote:> I'd like to isolate the second plot produced (the estimated functional > form of the influence of age on the log relative hazard) so that I can > use the 'points' function to add the linear predictors for the > untransformed and the log-transformed models. In the usual situation > one would produce a plot and then type: >I think predict(, type="terms") does what you want. -thomas Thomas Lumley Assoc. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle