1

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 Answers 2

2

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!)

Sign up to request clarification or add additional context in comments.

Comments

2

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.