不能改变R图中的pch(点符号)。相关

时间:2018-03-06 17:39:33

标签: r plot performanceanalytics

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

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

和我得到的,the correlation matrix plot。实际上,没有任何passthru参数可用(例如label,lty)。

2 个答案:

答案 0 :(得分:1)

编辑:请注意,根据打开的git hub票证,在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)

enter image description here

答案 1 :(得分:0)

&#34;形状&#34;也是数字编码的。 E. g。 pch = "+"相当于pch = 3pch = "." = pch = 46。有关列表,请参阅?points。在你的情况下,你可以尝试:

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