首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法更改R chart.Correlation中的点符号

无法更改R chart.Correlation中的点符号
EN

Stack Overflow用户
提问于 2018-03-06 17:39:33
回答 2查看 3.6K关注 0票数 2

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

代码语言:javascript
复制
install.packages("PerformanceAnalytics")
library(PerformanceAnalytics)   
chart.Correlation(iris[1:4], histogram=TRUE, pch=3)

我得到了什么,相关矩阵图。实际上,所有passthru参数都不起作用(例如标签、lty)。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-03-06 20:16:10

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

对此,我只是将...添加到pairs调用中:

代码语言:javascript
复制
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, ...)
}
代码语言:javascript
复制
chart.Correlation(iris[1:4], histogram=TRUE, pch=3)

票数 2
EN

Stack Overflow用户

发布于 2018-03-06 17:45:29

“形状”也是数字编码的。pch = "+"相当于pch = 3pch = "." = pch = 46。有关列表,请参见?points。在你的例子中,你可以尝试:

代码语言:javascript
复制
chart.Correlation(iris[1:4], histogram=TRUE, pch=3)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49136894

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档