[R] how to pass arguments to panel.cor in pairs()

Jinsong Zhao j@zh@o @ending from ye@h@net
Tue Oct 9 16:53:17 CEST 2018


Hi there,

Here is the panel.cor function from ?pairs:

     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))
         txt <- format(c(r, 0.123456789), digits = digits)[1]
         txt <- paste0(prefix, txt)
         if(missing(cex.cor)) cex.cor <- 0.8/strwidth(txt)
         text(0.5, 0.5, txt, cex = cex.cor * r)
     }

in the following code, pairs use the panel.cor defined above:

     pairs(USJudgeRatings, lower.panel = panel.smooth, upper.panel = panel.cor,
           gap=0, row1attop=FALSE)

I try to change prefix = "" to prefix = "r = ", something like:

     pairs(USJudgeRatings, lower.panel = panel.smooth, upper.panel = panel.cor, prefix = "r = ",
           gap=0, row1attop=FALSE)

I got lots of warnings.

How to change prefix to something else, but not change the defined panel.cor? Thanks!

Best,
Jinsong

	[[alternative HTML version deleted]]



More information about the R-help mailing list