Change the characters in the lower diagonal of the chart. Correlation()

Im tweaking PerformanceAnalytics chart.Correlation () function.

chart.Corr = function (R, histogram = TRUE, method = c("pearson", "kendall", 
    "spearman"), ...) 
{
    x = checkData(R, method = "matrix")
    if (missing(method)) 
        method = method[1]
    panel.cor <- function(x, y, digits = 2, prefix = "", use = "pairwise.complete.obs", 
        method, 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 = "")
        #print(txt)
        strwidth(txt)
        if (missing(cex.cor)) 
            cex <- 1.5 #/strwidth(txt)
        test <- cor.test(x, 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 * (abs(r) + 0.3)/1.3)
        text(0.5, 0.5, txt, cex = cex)
        text(0.7, 0.7, Signif, cex = cex-0.25, col = 1) #col = 2
    }
    f <- function(t) {
        dnorm(t, mean = mean(x), sd = sd.xts(x))
    }
    hist.panel = function(x, ...) {
        par(new = TRUE)
        hist(x, col = "light gray", probability = TRUE, axes = FALSE, 
            main = "", breaks = "FD", pch=".")
        lines(density(x, na.rm = TRUE), col = "blue", lwd = 1)
        rug(x)
    }
    print(x)
    print(class(x))
    if (histogram) 
        pairs(x, gap = 0, lower.panel = panel.smooth(pch="."), upper.panel = panel.cor, 
            diag.panel = hist.panel, method = method, ...) #(pch=".")
    else pairs(x, gap = 0, lower.panel = panel.smooth, upper.panel = panel.cor, 
        method = method, ...)
}

When I create an instance, I do not like my line lower.panel = panel.smooth(pch="."). In particular, it throws an error,

Error in points (x, y, pch = pch, col = col, bg = bg, cex = cex): the argument "x" is absent, without a default value

The error certainly applies to this line lower.panel. In the original function syntax, no arguments are passed to panel.smooth () at all, and it works without fail:

function (R, histogram = TRUE, method = c("pearson", "kendall", 
    "spearman"), ...) 
{
    x = checkData(R, method = "matrix")
    if (missing(method)) 
        method = method[1]
    panel.cor <- function(x, y, digits = 2, prefix = "", use = "pairwise.complete.obs", 
        method, 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(x, 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 * (abs(r) + 0.3)/1.3)
        text(0.8, 0.8, Signif, cex = cex, col = 2)
    }
    f <- function(t) {
        dnorm(t, mean = mean(x), sd = sd.xts(x))
    }
    hist.panel = function(x, ...) {
        par(new = TRUE)
        hist(x, col = "light gray", probability = TRUE, axes = FALSE, 
            main = "", breaks = "FD")
        lines(density(x, na.rm = TRUE), col = "red", lwd = 1)
        rug(x)
    }
    if (histogram) 
        pairs(x, gap = 0, lower.panel = panel.smooth, upper.panel = panel.cor, 
            diag.panel = hist.panel, method = method, ...)
    else pairs(x, gap = 0, lower.panel = panel.smooth, upper.panel = panel.cor, 
        method = method, ...)
}

I am trying to change the dot symbols in the scatterplots in the lower diagonal of a chart. I would prefer to do this by changing the syntax of panel.smooth () as described above, but I am open to other solutions.

+4
2

, , , , :

# Loading example data from PerformanceAnalytics
data(managers)

# running chart.Correlation with points set to "." (using the argument pch=".")
chart.Correlation(managers[,1:8], histogram=TRUE, pch=".")

- (, , ), , .

+2

, " " , . NOT: panel.smooth(pch="."). :

    panel.smooth(pch=".")
+3

All Articles