绘制每日时间序列

时间:2018-03-09 23:11:40

标签: r ggplot2 time-series

我有20个时间序列(日期,价格)。我正在尝试使用代码ggplot(timeseries, aes(x=date, y=price)) + geom_line(col="indianred", size= 1)

来绘制ggplot系列

我想问:我怎样才能在x轴上包含每一天?我在x轴上只有三天。

enter image description here

1 个答案:

答案 0 :(得分:1)

如果日期为1天,您可以使用以下scale_x_date(date_breaks = "1 day")包含每天。 (您也可以根据需要尝试"2 days""1 week"等字符串。)

lol <-tibble(date=c(Sys.Date()-7,Sys.Date()-6,Sys.Date()-5,Sys.Date()-4,Sys.Date()-3,Sys.Date()-2,Sys.Date()-1),price=c(1,23,21,9,6,2,32)) 

ggplot(lol, aes(x=date, y=price)) + geom_line(col="indianred", size= 1) + scale_x_date(date_breaks = "1 day")