-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpanelcor.R
21 lines (19 loc) · 895 Bytes
/
panelcor.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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="spearman"))
txt <- format(c(r, 0.123456789), digits=digits)[1]
txt <- paste(prefix, txt, sep="")
if(missing(cex.cor)) cex <- 0.8/strwidth(txt)
test <- cor.test(x,y)
# borrowed from printCoefmat
Signif <- symnum(test$p.value, corr = FALSE, na = FALSE,
cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1),
symbols = c("***", "**", "*", ".", " "))
#text(0.5, 0.5, txt, cex = cex * r) # if you want text size proportional to correlation
text(0.5, 0.5, txt, cex = 2)
#text(.8, .8, Signif, cex=cex, col=2) # if you want star symbol proportional to sign.
text(.8, .8, Signif, cex=4, col=2)
}
#pairs(iris[1:4], lower.panel=panel.smooth, upper.panel=panel.cor) #example result