I have a timeseries representation of my data as follows (without the row and column) annotations:
L1 L2 L3 L4
t=1 0 1 1 0
t=2 0 1 1 1
t=3 1 0 1 1
t=4 0 1 1 0
I am reading this into R as:
timeseries = read.table("./test", header=F)
I am plotting timeseries for L1 using
ts.plot(timeseries$V1)
and plotting the cross-correlation function as:
ccf(timeseries$V1, timeseries$V2)
Now, can someone please tell me how do I plot a cross correlation matrix that shows the output of this function for L1-L4? Basically, something like this (in my case, a 4x4 matrix of plots):
There seems to be another trivial way of doing it!
timeseries = read.table("./test", header=F)
acf(timeseries)
gives me a matrix of correlation plots. Of course, there are other options that can be passed to acf
if a covariance is needed.
A trivial way of doing this is to simply create a matrix of plots on your plotting device and place each ccf
plot in one by one:
M <- matrix(sample(0:1,40,replace = TRUE),nrow = 10)
par(mfrow= c(4,4))
for (i in 1:4){
for (j in 1:4){
ccf(M[,i],M[,j])
}
}
But if you wait around a bit, someone who knows the time series packages more intimately may swing by with a function that does this a bit more nicely.
Try this where M
is as in joran's post:
pnl <- function(x, y = x) { par(new = TRUE); ccf(x, y) }
pairs(as.data.frame(M), upper.panel = pnl, diag.panel = pnl, cex.labels = 1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With