无法更改 R chart.Correlation 中的 pch(点符号)

cannot change pch (point symbol) in R chart.Correlation

我使用 'performanceAnalytics' 包中的 'chart.Correlation' 来绘制相关矩阵图。但是我不能用 'pch' 参数更改点符号。这是代码,

install.packages("PerformanceAnalytics")
library(PerformanceAnalytics)   
chart.Correlation(iris[1:4], histogram=TRUE, pch=3)

以及我得到的,the correlation matrix plot。事实上,none 的直通参数有效(例如标签、lty)。

"shapes"也是用数字编码的。例如pch = "+" 等同于 pch = 3pch = "." = pch = 46。有关列表,请参阅 ?points。在您的情况下,您可以尝试:

chart.Correlation(iris[1:4], histogram=TRUE, pch=3)

编辑:请注意,根据打开的 git 中心票证,在 version 1.5.2 中删除了点以解决警告消息。因此请注意,虽然下面确实解决了所讨论的特定问题,但它可能会导致其他问题,具体取决于传递给函数的参数。

已修复,我刚刚将 ... 添加到 pairs 调用中:

chart.Correlation <- 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 = "pearson", 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 * (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))
    }
    dotargs <- list(...)
    dotargs$method <- NULL
    rm(method)
    hist.panel = function(x, ... = NULL) {
        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, ...)
    else pairs(x, gap = 0, lower.panel = panel.smooth, upper.panel = panel.cor, ...)
}

chart.Correlation(iris[1:4], histogram=TRUE, pch=3)