简体   繁体   English

R 中的相关性

[英]Correlation in R

I am trying to produce same graph as in example but using different data.我正在尝试生成与示例中相同的图表,但使用不同的数据。 Here is my code:这是我的代码:

library(SciViews)

args <- commandArgs(TRUE)
pdfname <- args[1]
datafile <- args[2]

pdf(pdfname)
eqdata = read.csv(datafile , header = T,sep=",")
(longley.cor <- correlation(eqdata$feqs))
# Synthetic view of the correlation matrix
summary(longley.cor) 
p <- plot(longley.cor)
print(p)
dev.off()   

and the data和数据

ques,feqs
"abc",20
"def",10
"ghi",40
"jkl",10
"mno",20
"pqr",10

I use this command我用这个命令

Rscript ./rscript/correlation.R "/home/co.pdf" "/home/data_correlation.csv"

在此处输入图像描述

Code output代码 output

在此处输入图像描述

I want to generate like this我想这样生成

在此处输入图像描述

You can try the plotcorr function in the ellipse package. The help pages gives among others this example:您可以在ellipse package 中尝试plotcorr function。帮助页面给出了以下示例:

在此处输入图像描述

Which seems to be what you are looking for?这似乎是你在找什么?

Edit:编辑:

You can add text afterwards, the circles are placed on a 1 - number of vars grid.您可以在之后添加文本,圆圈放置在 1 - vars 网格上。 Eg:例如:

data(mtcars)
Corrmat  <- cor(mtcars)
cols <- ifelse(Corrmat>0, rgb(0,0,abs(Corrmat)), rgb(abs(Corrmat),0,0))

library(ellipse)
plotcorr(Corrmat,col=cols)

n <- nrow(Corrmat)
for (i in 1:n)
{
    for (j in 1:n)
    {
        text(j,i,round(Corrmat[n-i+1,j],2),col="white",cex=0.6)     
    }
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM