Correlation in R

Go To


I am trying to produce same graph as in example but using different data. Here is my code:


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

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

and the data


I use this command

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

enter image description here

Code output

enter image description here

I want to generate like this

enter image description here

2012-04-04 04:55
by henna
Unfortunately I am not familiar with SciViews but still quite sure that computing correlation for only one variable of a data frame is not a good idea - daroczig 2012-04-04 05:17
Many thanks for you suggestion. I want to generate correlation of text... So just considering frequency of each word at the moment. Any idea for text correlation - henna 2012-04-04 05:33
If the variables you want to correlate are the frequencies of 'abc', `'def', etc., then you need more than one value for each variable. In your example each variable has only one value, and you cannot calculate the covariance of things that don't actually vary - Marius 2012-04-04 05:45
@Marius you are right. I have to format data like this

"abc","def","ghi","jkl","mno","pqr" 10,20,10,12,13,10 12,13,13,14,30,10 40,12,40,44,12,30

and its closer to my requirements - henna 2012-04-04 06:07


You can try the plotcorr function in the ellipse package. The help pages gives among others this example:

enter image description here

Which seems to be what you are looking for?


You can add text afterwards, the circles are placed on a 1 - number of vars grid. E.g.:

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


n <- nrow(Corrmat)
for (i in 1:n)
    for (j in 1:n)
2012-04-04 11:12
by Sacha Epskamp
thanks sacha, I need to display correlation on each ellipse. I could generate above graph but having problem with labels... in label instead of space its replaced with dot(.) do you have any idea,how to fix it - henna 2012-04-05 00:51
See edited answer - Sacha Epskamp 2012-04-05 05:02
I am still using SciViews package - henna 2012-04-05 06:16