-
Notifications
You must be signed in to change notification settings - Fork 0
/
chart.Correlation.R.txt
36 lines (31 loc) · 1.32 KB
/
chart.Correlation.R.txt
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
library('PerformanceAnalytics')
setwd("F:\\corr")
df<-read.csv("cor.csv",header=TRUE)
# df = read.delim("clipboard",header=TRUE)
df<- df[ ,-1]
mychart.Correlation <- function (R, method = c("pearson", "kendall", "spearman"), ...){
x = PerformanceAnalytics::checkData(R, method = "matrix")
if (missing(method)) method = method[1]
cormeth <- method
panel.cor <- function(x, y, digits = 2, prefix = "",
use = "pairwise.complete.obs",
method = cormeth,
cex.cor, ...) {
usr <- par("usr")
on.exit(par(usr))
par(usr = c(0, 1, 0, 1))
r <- cor(x, y, use = use, method = method)
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(as.numeric(x), as.numeric(y), 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("***", "**", "*", ".", " "))
text(0.5, 0.5, txt, cex = cex)
text(0.8, 0.8, Signif, cex = cex, col = 2)
}
pairs(x, gap = 0, lower.panel = panel.smooth, upper.panel = panel.cor, ...)
}
names(d1) <- gsub(" ", "\n", names(d1))
mychart.Correlation(df, method = "pearson", cex.labels = 2)