在R中以月-年格式绘制带有x轴刻度的时间序列图

在R中以月-年格式绘制带有x轴刻度的时间序列图,r,R,我无法使x轴以“Jan-99”格式显示刻度 纽约数据如下: head(rates,10) Month Repo_Rate 1 Apr-01 9.00 2 May-01 8.75 3 Jun-01 8.50 4 Jul-01 8.50 5 Aug-01 8.50 6 Sep-01 8.50 7 Oct-01 8.50 8 Nov-01 8.50 9 Dec-01 8.50 10 Ja

我无法使x轴以“Jan-99”格式显示刻度

纽约数据如下:

head(rates,10)
    Month Repo_Rate
1  Apr-01      9.00
2  May-01      8.75
3  Jun-01      8.50
4  Jul-01      8.50
5  Aug-01      8.50
6  Sep-01      8.50
7  Oct-01      8.50
8  Nov-01      8.50
9  Dec-01      8.50
10 Jan-02      8.50

sapply(rates,class)
      Month   Repo_Rate 
"character"   "numeric" 
如果我将“月”列转换为R的日期格式,仍然无法获得所需格式“Apr-01”的x轴刻度

此处需要帮助….

请尝试

library(xts)

xt1 <- xts(rates$Repo_Rate, order.by = as.yearmon(rates$Month, '%b-%y'))
plot(xt1)

图书馆(动物园)
图书馆(GG2)

fmt是的,很多,得到了情节…如果可以使用ts或动物园来完成,我们会更喜欢package@Nishant您也可以尝试
plot(使用(rates,zoo(Repo_Rate,order.by=as.yearmon(Month,'%b-%y')))
尽管我猜
xts
xtsExtra
库在设置x轴格式方面更灵活。嘿,我觉得这些plot提供了,我对样式的控制更少…使用ggplot wud肯定会给我更多的出版物级绘图。。。
library(zoo)

z1 <- with(rates, zoo(Repo_Rate, order.by= as.yearmon(Month, '%b-%y')))
plot(z1, xaxt = 'n')
tt <- time(z1)[seq(1, length(z1), by = 2)]
axis(1, tt, format(tt, '%b-%y'), las = 1)
library(zoo)
library(ggplot2)

fmt <- "%b-%y"
z <- read.zoo(rates, FUN = as.yearmon, format = fmt)
autoplot(z) + scale_x_yearmon(format = fmt)