Created
March 14, 2017 22:35
-
-
Save jasper1918/d914bc37982ff83e41577cde1ffecfcd to your computer and use it in GitHub Desktop.
my favorite pairs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pairs(df, lower.panel=panel.smooth, upper.panel=panel.cor, diag.panel=panel.hist) | |
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 <- 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*.8) | |
text(.8, .8, Signif, cex=cex*.8, col=2) | |
} | |
panel.hist <- function(x, ...) | |
{ | |
usr <- par("usr"); on.exit(par(usr)) | |
par(usr = c(usr[1:2], 0, 1.5) ) | |
h <- hist(x, plot = FALSE) | |
breaks <- h$breaks; nB <- length(breaks) | |
y <- h$counts; y <- y/max(y) | |
rect(breaks[-nB], 0, breaks[-1], y, col="cyan", ...) | |
} | |
panel.smooth <- function (x, y, col = par("col"), bg = NA, pch = par("pch"), | |
cex = 1, col.smooth = "red", span = 2/3, iter = 3, ...) | |
{ | |
points(x, y, pch = pch, col = col, bg = bg, cex = cex) | |
ok <- is.finite(x) & is.finite(y) | |
if (any(ok)) | |
lines(stats::lowess(x[ok], y[ok], f = span, iter = iter), | |
col = col.smooth, ...) | |
abline(a = 0,b = 1, col="blue", ...) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment