[R] "pairs" with same xlim and ylim scale
Shi, Tao
shidaxia at yahoo.com
Fri Sep 3 07:02:34 CEST 2010
Hi Dejian,
Thanks for the reply!
I finally found the problem. It is actually in the "panel.cor" function.
Adding "..." in the function and "text" call fixed everything.
Best,
...Tao
----- Original Message ----
> From: Dejian Zhao <dejian.zhao at gmail.com>
> To: r-help at r-project.org
> Sent: Thu, September 2, 2010 7:57:55 PM
> Subject: Re: [R] "pairs" with same xlim and ylim scale
>
> When "pairs" draws plots, "lower.panel" invokes "f.xy". Maybe there is
> something in "f.xy" incompatible with "pairs". You can read the code of
> "pairs" to see what happens.
>
> "pairs" has two methods, as you can see in the help message (?pairs).
> According to your code, pairs is supposed to invoke "Default S3 method".
> > methods(pairs)
> [1] pairs.default pairs.formula*
> Non-visible functions are asterisked
> Therefore, you should check the code of the function "pairs.default" to
> see how error occurs. Just type "pairs.default" at the R command prompt
> and enter, you can get the source code of "pairs.default".
>
>
>
> On 2010-9-2 15:15, Shi, Tao wrote:
> > Hi Dejian,
> >
> > You're right on this! Do you know how to pass those two argument into
> > lower.panel? Thanks!
> >
> > ...Tao
> >
> >
> > ________________________________
> > From: Dejian Zhao<zhaodj at ioz.ac.cn>
> > To:r-help at r-project.org
> > Sent: Tue, August 31, 2010 6:10:16 PM
> > Subject: Re: [R] "pairs" with same xlim and ylim scale
> >
> > I think you have successfully passed the "xlim" and "ylim" into the
> > function pairs1. Compare the two graphs produced by the codes you
> > provided, you can find the xlim and ylim in the second graph have been
> > reset to the assigned value. It seems that the program halted in
> > producing the second plot after adding xlim and ylim. According to the
> > error message, the two added parameters were not used in lower.panel, or
> > the customized function f.xy.
> >
> > On 2010-9-1 2:26, Shi, Tao wrote:
> >
> >> Hi list,
> >>
> >> I have a function which basically is a wrapper of pairs with some useful
>panel
> >> functions. However, I'm having trouble to pass the "xlim" and "ylim" into
>the
> >> function so the x and y axes are in the same scale and 45 degree lines are
> >> exactly diagonal. I've looked at some old posts, they didn't help much.
>I
> >>
> > [[elided Yahoo spam]]
> >
> >> Thanks!
> >>
> >> ...Tao
> >>
> >>
> >> pairs1<- function(x, ...) {
> >> f.xy<- function(x, y, ...) {
> >> points(x, y, ...)
> >> abline(0, 1, col = 2)
> >> }
> >>
> >> panel.cor<- function(x, y, digits=2, prefix="", cex.cor) {
> >> usr<- par("usr"); on.exit(par(usr))
> >> par(usr = c(0, 1, 0, 1))
> >> r<- abs(cor(x, y, method="p", use="pairwise.complete.obs"))
> >> txt<- format(c(r, 0.123456789), digits=digits)[1]
> >> txt<- paste(prefix, txt, sep="")
> >> if(missing(cex.cor)) cex<- 0.8/strwidth(txt)
> >> text(0.5, 0.5, txt, cex = cex * r)
> >> }
> >>
> >> panel.hist<- function(x, ...) {
> >> usr<- par("usr"); on.exit(par(usr))
> >> par(usr = c(usr[1:2], 0, 1.5) )
> >> h<- hist(x, plot = FALSE)
> >> breaks<- h$breaks; nB<- length(breaks)
> >> y<- h$counts; y<- y/max(y)
> >> rect(breaks[-nB], 0, breaks[-1], y, col="cyan", ...)
> >> }
> >>
> >> pairs(x, lower.panel=f.xy, upper.panel=panel.cor,
>diag.panel=panel.hist,
> >> ...)
> >> }
> >>
> >>
> >>
> >>> x<- rnorm(100, sd=0.2)
> >>> x<- cbind(x=x-0.1, y=x+0.1)
> >>> pairs1(x)
> >>> pairs1(x, xlim=c(-1,1), ylim=c(-1,1))
> >>>
> >>>
> >> Error in lower.panel(...) :
> >> unused argument(s) (xlim = c(-1, 1), ylim = c(-1, 1))
> >>
> >>
> >>
> >> [[alternative HTML version deleted]]
> >>
> >> ______________________________________________
> >> R-help at r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting
>guidehttp://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >>
> >>
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
> >
>
> ______________________________________________
> 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.
>
More information about the R-help
mailing list