[英]how to plot time series with x axis ticks in month-year format in ggplot
[英]how to plot multiple time series in “month-year” x-axis ticks using ggplot
我想在一個繪圖窗口中繪制多個時間序列。
個別地,我也無法做到這一點。然后如何繪制多個時間序列。
這是數據
head(MP_rates)
Month repo revrepo bankrate CRR WPI
1 Apr-01 9.00 6.75 7 8.0 5.41
2 May-01 8.75 6.50 7 7.5 5.60
3 Jun-01 8.50 6.50 7 7.5 5.30
4 Jul-01 8.50 6.50 7 7.5 5.23
5 Aug-01 8.50 6.50 7 7.5 5.41
6 Sep-01 8.50 6.50 7 7.5 4.52
sapply(MP_rates,class)
Month repo revrepo bankrate CRR
"character" "numeric" "numeric" "numeric" "numeric"
WPI
"numeric"
我嘗試在單個時間序列中執行此操作:
rates$date <- as.character(rates$Month,stringAsFactors = FALSE)
rates$date <- as.Date(rates$date, "%B-%d")
head(rates)
Month repo date
1 Apr-01 9.00 2015-04-01
2 May-01 8.75 2015-05-01
3 Jun-01 8.50 2015-06-01
4 Jul-01 8.50 2015-07-01
5 Aug-01 8.50 2015-08-01
6 Sep-01 8.50 2015-09-01
這一直持續到2015年9月
ggplot(rates)+ geom_line(aes(x=date,y=repo))+
scale_x_date(labels =date_format("%b-%d"))
我沒有獲得整個15年的單一時間序列圖...它只是繪制一年的數據。
嘗試更改格式scale_x_date(labels = date_format("%Y-%B"))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.