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]]
On 09/10/2018 10:53 AM, Jinsong Zhao wrote:> 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!Since panel.cor is not a base function, just a function defined in the example, you could just modify it. If you want the regular one sometimes and a custom one other times, you could make your own panel function: panel.cor2 <- function(...) panel.cor(..., prefix = "r = ") Then use pairs(USJudgeRatings, lower.panel = panel.smooth, upper.panel = panel.cor2, gap=0, row1attop=FALSE) Duncan Murdoch
On 2018/10/9 23:22, Duncan Murdoch wrote:> On 09/10/2018 10:53 AM, Jinsong Zhao wrote: >> 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! > > Since panel.cor is not a base function, just a function defined in the > example, you could just modify it. > > If you want the regular one sometimes and a custom one other times, > you could make your own panel function: > > ? panel.cor2 <- function(...) panel.cor(..., prefix = "r = ") > > Then use > > > ? pairs(USJudgeRatings, lower.panel = panel.smooth, upper.panel = > panel.cor2, gap=0, row1attop=FALSE) >That is what I want to know. Thanks a lot. Best, Jinsong