簡體   English   中英

更改圖表下對角線上的點字符。相關()

[英]Change point characters in lower diagonal of chart.Correlation()

我正在調整PerformanceAnalytic的chart.Correlation()函數。

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, ...)
}

當我實例化時,它不喜歡我的lower.panel = panel.smooth(pch=“.”)行。 具體來說,它會拋出錯誤,

點錯誤(x,y,pch = pch,col = col,bg = bg,cex = cex):缺少參數“x”,沒有默認值

該錯誤肯定是指lower.panel行。 在函數的原始語法中,沒有任何參數傳遞給panel.smooth(),並且它運行沒有故障:

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, ...)
}

我正在嘗試更改圖表下對角線中散點圖中的點字符。 我更喜歡通過調整如上所述的panel.smooth()語法來實現它,但我對其他解決方案持開放態度。

我猜你用“文字處理器”進行了編輯,或者將它復制成一個用常規引號代替smate-quotes的網站。 NOT: panel.smooth(pch=“.”) 嘗試改為:

    panel.smooth(pch=".")

如果我誤解了你的問題,請原諒我,但如果你只是試圖讓對角線左下方的散點圖使用一個點,那么這段代碼將為你做到:

# 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=".")

如果您正在嘗試完成更復雜的事情(因此需要編輯函數本身),請澄清問題,我將更新我的答案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM