File: correlation_matrix_plot.rkcommands.R

package info (click to toggle)
rkward 0.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 45,628 kB
  • sloc: cpp: 50,489; xml: 9,596; javascript: 6,401; python: 21; makefile: 13
file content (38 lines) | stat: -rw-r--r-- 1,135 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
local({
## Prepare
cor.graph <- function(x) {
	panel.cor <- function(x, y, digits=3, cex.cor, use="pairwise.complete.obs", method="pearson", scale=TRUE) {
		usr <- par("usr"); on.exit(par(usr=usr))
		par(usr = c(0, 1, 0, 1))
		r <- abs(cor(x, y, use=use, method=method))
		txt <- format(c(r, 0.123456789), digits=digits)[1]
		if(missing(cex.cor)) cex <- 0.8/strwidth(txt)
	
		test <- cor.test(x,y, use=use, method=method)
		Signif <- symnum(test$p.value, corr = FALSE, na = FALSE,
				cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1),
				symbols = c("***", "**", "*", ".", " "))

		if(scale) text(0.5, 0.5, txt, cex = cex * r)
		else text(0.5, 0.5, txt, cex = cex)
		text(.8, .8, Signif, cex=cex, col=2)
	}

	pairs(x, lower.panel=panel.smooth, upper.panel=panel.cor)
}
## Print result
data <- data.frame (rock)

rk.header ("Correlation Matrix Plot", parameters=list("Method"="Pearson",
	"Exclude missing values"="pairwise",
	"Precision (digits)"="3",
	"Scale text"="yes"))

rk.graph.on ()
try ({
	cor.graph (data)
})
rk.graph.off ()

rk.print("Legend:\t'***': p &lt; 0.001 -- '**': p &lt; 0.01 -- '*': p &lt; 0.05 -- '.'': p &lt; 0.1")
})