[R] Adding text (coefts) to pairs panels
Mark Van De Vyver
mvdv at spamcop.net
Wed Mar 3 20:17:24 CET 2004
Andy,
Thank you very much - that works and shows me how to go about working out
the range of possible values for the position co-ords.
Much appreciated.
Mark
> -----Original Message-----
> From: Liaw, Andy [mailto:andy_liaw at merck.com]
> Sent: Thursday, March 04, 2004 2:07 AM
> To: 'Mark Van De Vyver'; r-help at stat.math.ethz.ch
> Subject: RE: [R] Adding text (coefts) to pairs panels
>
>
> You need to figure out the "user coordinates" for each panel,
> so you can put the text within the range that's being
> plotted. Here's an example:
>
> panel.myfitline <- function(x, y, digits=2, prefix="", cex.cor, ...) {
> usr <- par("usr")
> res<-panel.smooth(x,y, col.smooth="blue", ...)
> reg <- coef(lm(y ~ x))
> abline(coef=reg,untf=F)
> const<-format(reg[1], trim = FALSE, digits = NULL, nsmall
> = 0, justify = "left", ...)
> const<-paste(prefix, const, sep="")
> slope<-format(reg[2], trim = FALSE, digits = NULL, nsmall
> = 0, justify = "left", ...)
> slope<-paste(prefix, slope, sep="")
> if(missing(cex.cor)) cex <- 0.8/strwidth(const)
> text(.95*usr[2], usr[3] +.05*(usr[4]-usr[3]), const, cex=cex)
> if(missing(cex.cor)) cex <- 0.8/strwidth(slope)
> text(usr[1] + .1*(usr[2]-usr[1]), .98*usr[4], slope, cex=cex) }
>
> HTH,
> Andy
>
> > From: Mark Van De Vyver
> >
> > Hi,
> > First of all, thanks for the efforts of all the developers
> > and contributors
> > - I'm very new to R and at the moment am just using it to
> create some
> > graphics, but it seems to be quite powerful.
> > I've googled the archives and wasn't able to find anyhting
> > that dealt with
> > this problem, so would appreciate any suggestions/tips.
> >
> > In a pairs plot I'd like to plot a linear regression line in
> > each panel and,
> > also in each panel, I'd like to have some text in the panel
> > showing the
> > coefts, etc.
> > I'm able to get the regressions line plotted, but not the
> > text/coefficients.
> > Using one of the R examples, example(pairs), I have got this far:
> >
> > panel.myfitline<-function(x, y, digits=2, prefix="", cex.cor, ...) {
> > res<-panel.smooth(x,y, col.smooth="blue", ...)
> > reg <- coef(lm(y ~ x))
> > abline(coef=reg,untf=F)
> > const<-format(reg[1], trim = FALSE, digits = NULL, nsmall
> > = 0, justify =
> > "left", ...)
> > const<-paste(prefix, const, sep="")
> > slope<-format(reg[2], trim = FALSE, digits = NULL, nsmall
> > = 0, justify =
> > "left", ...)
> > slope<-paste(prefix, slope, sep="")
> > if(missing(cex.cor)) cex <- 0.8/strwidth(const)
> > text(0.1, 0.5, const, cex=cex)
> > if(missing(cex.cor)) cex <- 0.8/strwidth(slope)
> > text(0.5, 0.1, slope, cex=cex)
> > }
> > pairs(USJudgeRatings[1:5], lower.panel=panel.smooth,
> > diag.panel=panel.hist,
> > upper.panel=panel.myfitline)
> >
> > Mark Van De Vyver
> > PhD
> > Lecturer
> > Finance Discipline
> > School of Business
> > Faculty of Economics and Business
> > Economics & Business Building H69
> > The University of Sydney
> > Sydney NSW 2006 Australia
> > Telephone: +61 2 9351-6452
> > Fax: +61 2 9351-6461
> > Mobile: 0428 281407
> >
> mailto:mvdv at spamcop.net
> http:\\www.econ.usyd.edu.au
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo> /r-help
> PLEASE
> do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>
>
> --------------------------------------------------------------
> ----------------
> Notice: This e-mail message, together with any attachments,
> contains information of Merck & Co., Inc. (One Merck Drive,
> Whitehouse Station, New Jersey, USA 08889), and/or its
> affiliates (which may be known outside the United States as
> Merck Frosst, Merck Sharp & Dohme or MSD and in Japan, as
> Banyu) that may be confidential, proprietary copyrighted
> and/or legally privileged. It is intended solely for the use
> of the individual or entity named on this message. If you
> are not the intended recipient, and have received this
> message in error, please notify us immediately by reply
> e-mail and then delete it from your system.
> --------------------------------------------------------------
> ----------------
>
More information about the R-help
mailing list