2013-12-07 49 views
-3

我有一個data frame情節的時間序列數據幀

     BA HRS SPR TGI 
11/21/2006 00:00:00 91.10 43.55 29.00 25.925 
11/22/2006 00:00:00 90.10 44.57 29.35 26.025 
11/24/2006 00:00:00 89.77 44.02 28.80 25.880 
11/27/2006 00:00:00 87.37 42.46 28.39 25.800 
11/28/2006 00:00:00 87.94 41.91 28.31 25.970 
11/29/2006 00:00:00 88.89 42.40 29.02 26.455 

我想與ggplot繪製時間序列,都在一起,有日期,行名稱爲x軸。

我對R非常新,我希望有一些樣板代碼可以開始試驗圖書館。

回答

3

使時間成爲數據框(df)的第一列並調用列「time」。

require(ggplot2) 
require(reshape2) 
df$time <- as.POSIXct(df$time, format = "%m/%d/%Y %H:%M:%S") 
df.m <- melt(df, id.vars = "time") 
ggplot(df.m) + geom_line(aes(x = time, y = value, colour = variable)) 

食譜的R是巨大的。