2016-05-04 17 views
4

PerformanceAnalyticのchart.Correlation()関数を調整しています。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" の既定値はありません

で、欠落しています。具体的には、

エラーの点では、(X、Y、PCH = PCH、COL = COL、BG = BG、CEX = CEX)、エラーがスローされます

エラーは間違いなくその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()の構文を微調整することでやりたいと思っていますが、他のソリューションにも対応しています。

答えて

2

私はあなたの質問を誤解していた場合、私を許して、しかし、あなただけのドットを使用するように対角線の左下にある散布図を取得しようとしている場合、このコードは、あなたのためにそれを行うだろう。あなたがより複雑な何かを達成(したがって機能、自体を編集する必要がある)しようとしている場合

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

は、質問を明確にしてください、私は私の答えを更新します。

+0

この単純な答えで十分です。@enpitsu;これ(smh)のおかげで。 私は他の理由で機能を変更する予定ですが、これに感謝します! – Atticus29

+0

うれしい私は助けることができました! – enpitsu

+0

申し訳ありません。間違った答えに賞金を与えました。あなたに23時間で大きなものを与える。 – Atticus29

3

「ワードプロセッサ」で編集したか、それをコピーして通常の引用符に代わる引用符で置き換えたサイトをコピーしたと思います。 NOT:panel.smooth(pch=“.”)。代わりに試してみてください:

panel.smooth(pch=".") 
関連する問題