简体   繁体   English

如何从chart.correlation函数中删除有效星

[英]How to remove significance stars from chart.correlation function

I'm using the performance analytics chart.correlation program for 13 variables. 我正在使用13个变量的性能分析chart.correlation程序。 I want to remove the significance stars from the upper quadrant. 我想从上象限中删除重要的星星。

I have tried using the ... and then adding "stars = FALSE" and other combinations based on reading what dependencies this package uses. 我已经尝试使用...然后添加“stars = FALSE”和其他组合,基于读取此包使用的依赖项。 This is a basic question that if answered will teach myself and others how to properly look up dependencies and how to change them in R packages. 这是一个基本问题,如果回答将教会我自己和其他人如何正确查找依赖关系以及如何在R包中更改它们。

library(PerformanceAnalytics)
my_data <- mtcars[, c(1,3,4,5,6,7)]
chart.Correlation(my_data, histogram = TRUE, pch = 19)

As expected there are bright red stars for significant p-values. 正如预期的那样,对于显着的p值,存在明亮的红色恒星。 Any help in making them disappear is appreciated. 任何帮助他们消失的人都会受到赞赏。

If you look at the code for chart.Correlation you can see that the stars are generated via symnum() . 如果你查看chart.Correlation的代码,你可以看到星星是通过symnum()生成的。 You can create a copy of the function and comment this and the call to text() that places them out. 您可以创建该函数的副本并对此进行注释,并调用text()将它们放置出来。

chart.Correlation.nostars <- 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.nostars(my_data)

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何更改R中PerformanceAnalytics库中chart.Correlation的颜色? - How to change the colors of chart.Correlation from PerformanceAnalytics library in R? 图表与连续和类别变量的相关性 - chart.Correlation with continious and categorical variables R ggplot2 是否有等效于 Performance Analytics 包中的 chart.Correlation 函数? - R ggplot2 is there are equivalent to the chart.Correlation function in the Performance Analytics package? 如何使用ggplot2包创建此图表.R中的相关图? - How can I create this chart.Correlation graph in R using the ggplot2 package? 我如何使用 colnames 作为chart.Correlation 的标签,如 corrplot - How do i use colnames as labels for chart.Correlation like in corrplot 如何增加 PerformanceAnalytics::chart.Correlation 和断线中变量名称的大小? - How to increase the size of the name of variables in PerformanceAnalytics::chart.Correlation and break line? 具有重要性星的非平方相关矩阵的相关图 - Correlation plots for non square correlation matrix with significance stars 无法更改 R 图中的 pch(点符号)。相关性 - cannot change pch (point symbol) in R chart.Correlation 更改图表下对角线上的点字符。相关() - Change point characters in lower diagonal of chart.Correlation() chart.correlation独立与因变量的可视化 - chart.Correlation independent vs dependent variables visualisation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM