gpt4 book ai didi

r - 更改 chart.Correlation() 下对角线中的点字符

转载 作者:行者123 更新时间:2023-12-04 09:33:16 25 4
gpt4 key购买 nike

我正在调整 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=“.”) 行。具体来说,它抛出错误,

Error in points(x, y, pch = pch, col = col, bg = bg, cex = cex) : argument "x" is missing, with no default



错误肯定是指那个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 代替常规引号。不是:panel.smooth(pch=“.”) .试试吧:

    panel.smooth(pch=".")

关于r - 更改 chart.Correlation() 下对角线中的点字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37035373/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com