2011-07-14 32 views
8

我有一个时间序列数据如下所示:时间序列barplot中的R

x <- structure(list(date = structure(c(1264572000, 1266202800, 1277362800, 
1277456400, 1277859600, 1278032400, 1260370800, 1260892800, 1262624400, 
1262707200), class = c("POSIXt", "POSIXct"), tzone = ""), data = c(-0.00183760994446658, 
0.00089738603087497, 0.000423513598318936, 0, -0.00216496690393131, 
-0.00434836817931339, -0.0224199153445617, 0.000583823085470003, 
0.000353088613905206, 0.000470295331234771)), .Names = c("date", 
"data"), row.names = c("1", "2", "3", 
"4", "5", "6", "7", "8", "9", "10" 
), class = "data.frame") 

和由此每个条代表每个日期我将使这个数据集的barplot(如果存在用于入库时间没有DATAS,有应该是差距)。

任何人都可以帮助我吗?

+5

+1对于使用'dput'重建数据。欢迎来到SO。 – Andrie

回答

14

使用ggplot :(注意,您必须提供stat="identity"geom_bar以防止汇总数据和创建直方图)。

library(ggplot2) 
ggplot(x, aes(x=date, y=data)) + geom_bar(stat="identity") 

enter image description here

如果你倾向于使用基显卡:

plot(x$date, x$data, type="h") 

enter image description here

+0

谢谢,这非常有帮助! – Atticus

+1

+1和ggplot2表示。 –