2

这可能是一个简单的问题。我有一个 df,我想在 R 中为我的数据生成一个相关图。

head(df)

            x  y
1 -0.10967469  1
2  1.06814661 93
3  0.71805993 46
4  0.60566332 84
5  0.73714006 12
6 -0.06029712  5

我找到了一个名为corPlot的包,并且基于 pearson & spearman 方法生成了两个图。

corPlot(df, method = 'pearson')
corPlot(df, method = 'spearman')

这是我使用 pearson 方法的输出:

在此处输入图像描述

我想知道是否有另一个包可以生成我不知道的相同相关图?

提前致谢,

4

3 回答 3

1

还有另一个库 corrplot

library(corrplot)
cor.table = cor(df)
corrplot(cor.table)

在此处输入图像描述

于 2020-04-17T04:39:12.027 回答
0

试试 corrplot 库,这里是这个链接的一个例子

library(corrplot)
M <- cor(mtcars)
corrplot(M, method = "circle")
于 2015-08-12T14:49:15.103 回答
0

你应该检查一下?pairs。它非常适合为变量组合绘制散点图,但可以改变显示在

  1. 下三角形(将 2 个变量传递给lower.panel参数的传递函数)
    • 例如,pairs(df, lower.panel=points对于散点图
  2. 对角线(将 1 个变量传递给diag.paneltext.panel参数的函数)
    • 这很棘手!有关如何制作直方图的信息,请参阅帮助文件
  3. 上三角形(将 2 个变量作为参数的传递函数upper.panel
    • 例如,,pairs(df, upper.panel=function(x,y)text(0,0,cor(x,y)))但见下文

散点图和相关性,来自帮助文件 ( ?pairs):

panel.cor <- function(x, y, digits = 2, prefix = "", cex.cor, ...)
{
    usr <- par("usr"); on.exit(par(usr))
    par(usr = c(0, 1, 0, 1))
    r <- abs(cor(x, y))
    txt <- format(c(r, 0.123456789), digits = digits)[1]
    txt <- paste0(prefix, txt)
    if(missing(cex.cor)) cex.cor <- 0.8/strwidth(txt)
    text(0.5, 0.5, txt, cex = cex.cor * r)
}
pairs(USJudgeRatings, lower.panel = panel.smooth, upper.panel = panel.cor)

使用您的数据,执行以下操作:

pairs(df, lower.panel=plot, upper.panel=panel.cor)

我喜欢这个功能,并按原样使用它。x只有 an和 a可能看起来有点奇怪y,但是

于 2015-08-12T15:44:21.420 回答