rCharts - interactive matrix plot

81 views Asked by At

I have a horizontally oriented matrix with x = time and y = stocks' returns. I'd like to plot it with rCharts to make it interactive but I can't find HOW anywhere...

matrix is like:

matTest <- as.data.frame(matrix(rnorm(100,0,1), nrow = 5, ncol = 10))
colnames(matTest) <- c('t0','t1','t2','t3','t4','t5','t6','t7','t8','t9')
rownames(matTest) <- c('stock1','stock2','stock3', 'stock4','stock5')

do you know how can I do that?

Thank you very much

1

There are 1 answers

2
Terru_theTerror On

If you need an interactive table, you can use this code on your original data.

library(DT)
datatable(matTest, options = list(pageLength = 9))

InteractiveTable

If you want an interactive time_series plot, first of all change the format of your data in this way:

df<-as.data.frame(cbind(as.matrix(as.vector(t(matTest))),c(1:ncol(matTest)-1),unlist(lapply(rownames(matTest),rep,times=ncol(matTest)))))
colnames(df)<-c("time_series","time","stock")
df
           time_series time stock
1   -0.813688587253615    0     1
2   -0.457763419325742    1     1
3   0.0756429812511287    2     1
4     2.18700453503453    3     1
5     1.00659661717065    4     1
6    -2.16436341755656    5     1
7  -0.0829999360152501    6     1
8   -0.491237208736282    7     1
9    0.351591891565934    8     1
10   0.138073915553248    9     1
11   0.276431050047784    0     2
12   -0.88208290628419    1     2
13   0.421498167781597    2     2
...

Now use rCharts to plot yout time_series

library("rCharts")
xPlot(time_series~time, group="stock",data=df,type="line-dotted")

xPlot

Now you can change the plot's parameters to have the best outfit.