【问题标题】:How to plot corr.test output?如何绘制 corr.test 输出?
【发布时间】:2021-02-02 14:03:30
【问题描述】:

我有两个具有相同行数和不同列数的数据框。我使用 psych 包执行 corr.test

Correlations <- corr.test(final_x, final_y, use = "pairwise", alpha=0.05, method = "spearman")

现在我在运行corr.test 后确实有输出(例如相关性)。我可以单独保存Correlation$pCorrelation$r 并制作热图。

但我的问题是我想绘制Correlation 本身的对角线图,Correlation$p 在图的右上角,Correlations$r 在图的左下角。

我试过了,但没有帮助:

corPlot(Correlations,numbers=TRUE,colors=TRUE,n=51,main=NULL,zlim=c(-1,1),
        show.legend=TRUE, labels=NULL,n.legend=10,keep.par=TRUE,select=NULL, pval=NULL,  
        cuts=c(.001,.01),scale=TRUE,cex,MAR,upper=TRUE,diag=TRUE, symmetric=TRUE,stars=FALSE,
        adjust="holm",xaxis=1, xlas=0,ylas=2,gr=NULL,alpha=.75,min.length=NULL)

如果你能给我一些帮助,那就太好了。

谢谢

【问题讨论】:

    标签: r ggplot2 plot correlation


    【解决方案1】:

    这个例子可能会有所帮助:

    mcor <- cor(mtcars) # correlation matrix
    mcor
    mydata=mtcars
    library(corrplot)
    corrplot(mcor, type="upper", order="hclust", tl.col="black", tl.srt=45) # print correlation 
    

    打印散点图:

    library("ggpubr")
    data=iris
    str(data)
    ggscatter(data, x = "Sepal.Length", y = "Petal.Length", 
              add = "reg.line", conf.int = TRUE, 
              cor.coef = TRUE, cor.method = "pearson",
              xlab = "xlab", ylab = "ylab")
    

    用于绘图;

    library("ggpubr")
    library("Hmisc")
    mydata=mtcars
    mydata.rcorr = rcorr(as.matrix(mydata))
    mydata.coeff = mydata.rcorr$r
    mydata.p = mydata.rcorr$P
    plot(mydata.coeff,mydata.p)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-22
      • 2015-07-20
      • 1970-01-01
      • 2017-03-02
      • 2018-10-28
      • 2019-01-19
      • 2017-12-24
      • 1970-01-01
      相关资源
      最近更新 更多