1
votes

I am trying to plot the correlation between dependent variables of two time series.

Data 1
======
1    3.1
2    3.3
3    3.1
4    4.5
...
...

Data 2
========
1    3.1
2    0.3
3    4.1
4    3.2
...
...

I am using R.

library(corrplot)
foo <- read.table("D:\\datas\\res\\A.txt", header=T,sep=",")
attach(foo)
foo1 <- read.table("D:\\datas\\res\\M.txt", header=T,sep=",")
attach(foo1)
res<-cor(foo$col1, foo1$col2)
corrplot(res, type="upper", order="hclust",     tl.col="black", tl.srt=45)

Getting error:

Error in corrplot(cor(foo$col1, foo1$col2), type = "upper", order = "hclust", : Need a matrix or data frame!

I see only two values in 'z'. How can I convert this from vector form to matrix form?

2

2 Answers

2
votes

First make a data frame:

data_sel <-data.frame(foo$col1, foo1$col2)
res <- cor(data_sel)
corrplot(res, type="upper", order="hclust", tl.col="black", tl.srt=45)

(and try to prevent using attach!)

2
votes

corrplot is a correlation matrix, i.e. the pairwise correlations between the variables denoted by the columns and rows. You only have one correlation value, therefore you can't really plot it like that (see edit).

EDIT:

Yeah, you can actually plot it, but it's useless, as you know beforehand there's only one useful value in the matrix;