[R] "pairs" with same xlim and ylim scale

Dejian Zhao zhaodj at ioz.ac.cn
Wed Sep 1 03:10:16 CEST 2010


 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
> think this is b/c I have multiple panel functions.  Help!
>
> 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 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