2013-04-05 75 views
1

我有一个100 * 8数据矩阵,其中每行是8个不同时间点的值向量。我想知道如何绘制R中下面的矩阵来获得图形非常类似下面的一个:绘制时间序列数据矩阵点向量

enter image description here

这里是我的数据矩阵的一个例子。

  1 2  3  4 5 6 7  8 
line1  0.22 0.075 0.35 0.89 0 0.35 0.42 2.34 
line2  0 0.47 0.89 2.51 0 0.36 1.14 2.09 
line3  1.22 0.075 0.35 0.89 0 0.35 0.42 1.34 
line4  2.22 0.75 0.45 0.99 0 0.54 0.24 2.34 
line5  3.22 0.275 0.55 0.819 0 0.25 0.34 2.34 

任何帮助或建议将不胜感激。谢谢。

回答

6

尝试matplot()。默认情况下,它将列视为系列,因此我们需要在使用前转置(t())数据帧。下面是使用数据的子集,您所提供

timeser <- read.table(text = "   1 2  3  4 5 6 7  8 
line1  0.22 0.075 0.35 0.89 0 0.35 0.42 2.34 
line2  0 0.47 0.89 2.51 0 0.36 1.14 2.09 
line3  1.22 0.075 0.35 0.89 0 0.35 0.42 1.34 
line4  2.22 0.75 0.45 0.99 0 0.54 0.24 2.34 
line5  3.22 0.275 0.55 0.819 0 0.25 0.34 2.34", header = TRUE) 

matplot(t(timeser), type = "l") 

为例生产

enter image description here

+0

真棒..感谢.. – snape 2013-04-05 03:55:42

5

您可以转换您反对zoo对象,然后使用plot.zoo,从而获得所需的情节。 zoo是时间序列类。

> mat 
     X1 X2 X3 X4 X5 X6 X7 X8 
[1,] 0.22 0.075 0.35 0.890 0 0.35 0.42 2.34 
[2,] 0.00 0.470 0.89 2.510 0 0.36 1.14 2.09 
[3,] 1.22 0.075 0.35 0.890 0 0.35 0.42 1.34 
[4,] 2.22 0.750 0.45 0.990 0 0.54 0.24 2.34 
[5,] 3.22 0.275 0.55 0.819 0 0.25 0.34 2.34 

> plot.zoo(zoo(t(mat), order.by=1:ncol(mat)), screens = 1, col = rainbow(ncol(t(mat))), ylab="Data") 

这会给

enter image description here

+0

真棒..感谢.. – snape 2013-04-05 20:43:48